I have the following code:
<?php
$post_test = filter_input(INPUT_POST, 'test');
if (isset($post_test)) {
echo 'has data';
// ********************
// it is not going here
// ********************
}
<form role="form" action="" method="post">
// some form fields here
<button type="submit" name="test" class="form-button" onclick="this.form.submit(); this.disabled=true; ">Send</button>
</form>
I want to disable the button when i submit. But it is not going inside the php code I highlighted above and there's no data. So I resorted to this just to fake the disabling:
<form role="form" action="" method="post">
<button type="submit" name="test" class="form-button" onclick="this.className='button-disabled'; this.innerHTML='Sending...'; ">Send</button>
</form>
Please advise.
Updated
<?php
$post_test = filter_input(INPUT_POST, 'test');
if (isset($post_test)) {
echo 'has data';
// ********************
// it is not going here
// ********************
}
?>
<form role="form" action="" method="post">
// some form fields here
<button type="submit" name="test" value="1" class="form-button" onclick="this.form.submit(); this.disabled=true; this.className='button-disabled'; this.innerHTML='Sending...'; ">Send</button>
</form>
Instead of performing the check on the name of the submit button, create an hidden element with name test and value 1.
<form role="form" action="" method="post">
<input type="hidden" name="test" value="1" />
<button type="submit" class="form-button" onmouseup="this.form.submit(); this.disabled=true; this.className='button-disabled'; this.innerHTML='Sending...'; ">Send</button>
</form>
Related
I have two form with submit button in php file
when click on first submit button url become
http://url.com/?valueI=Want
when click second submit button: I need url become http://url.com/
without parameter
How i can do this please
<?php
if (isset($_POST['ASK_Button'])) {
}
if (isset($_POST['SET_Button'])) {
}
?>
<html>
<body>
<form id="ASKUser" class="blocks" action="#" method="post">
<input type="submit" Name="ASK_Button" value="ASK">
</form>
<form id="SETUser" class="blocks" action="#" method="post">
<input type="submit" Name="SET_Button" value="SET">
</form>
</body>
</html>
Change your ask form method to GET
<?php
if (isset($_GET['ASK_Button'])) {
}
if (isset($_POST['SET_Button'])) {
}
?>
<html>
<body>
<form id="ASKUser" class="blocks" action="#" method="GET">
<input type="text" name="valuel" value="Want">
<input type="submit" Name="ASK_Button" value="ASK">
</form>
<form id="SETUser" class="blocks" action="#" method="post">
<input type="submit" Name="SET_Button" value="SET">
</form>
</body>
</html>
With use of action attribute. Set it how you need. Or change it in onSubmit form handler.
is possible to show the 2nd form? after clicked the 1st form submit button? and is there a way to hide the second form?
example
<?php
if(isset($_POST['submit']))
{ #show form 2
}
?>
<form action="" method="post" name="form1">
<input type="submit" name="submit">
</form>
if theres a way to hide form 2
<form action="" method="post" name="form2">
<input type="submit" name="submit">
</form>
thanks in advance fellow web developers
Yes. Move the condition down.
<form action="" method="post" name="form1">
<input type="submit" name="submit">
</form>
<?php if (isset($_POST['submit'])) { ?>
<form action="" method="post" name="form2">
<input type="submit" name="submit">
</form>
<?php } ?>
But note that, you have the same name in both the form's submit button, so it is better to disable the previous form's submit:
<form action="" method="post" name="form1">
<input type="submit" name="submit"<?php if (isset($_POST['submit'])) { echo ' disabled="disabled"'; } ?>>
</form>
<?php if (isset($_POST['submit'])) { ?>
<form action="" method="post" name="form2">
<input type="submit" name="submit">
</form>
<?php } ?>
<?php
echo $_POST['textvalue'];
echo $_post['radiovalue'];
?>
<div id="hidethis">
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</div>
http://jsfiddle.net/Bjk89/2/ here is it with the jQuery.
What i try to do is to hide the <div id="hidethis"> when it's clicking submit.
I know i can make another page where i can recieve the values without the <form> section, but i want to put both in one page, make the <div id="hidethis"> hidden after submit.
So i'll be able to get echo $_POST['textvalue']; and echo $_post['radiovalue']; as results
RESULT MUST BE LIKE
A Text // This is the value you input into Tekst Value
autogivevalue // This is the value from the radio button
----- INVISIBLE -----
<form is hidden because we set it in jQuery so>
</form>
Try this. No need to use jQuery here.
<?php
if($_POST) {
echo $_POST['textvalue'];
echo $_post['radiovalue'];
} else {
?>
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</form>
<?php
}
?>
Try adding '#' in your jquery code. Your version does not have # next to submit. Also your form is missing a closing tag here and in your JSFiddle code.
Try this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#submit').click(function () {
$('form').submit();
$('#hidethis').hide();
});
});
</script>
<form method='post' id="hidethis" name='form'>
<input type="text" name="textvalue">
<input type="radio" name="radiovalue" value="1">
<input type="button" id="submit" name="submit" value="submit">
</form>
i am a beginner in php and my first task is to build a calculator and I am here to ask how to get a value from a button and just echo it on the same page. I am trying through method post using isset but enable to display any value on the same page.
<form action="" method="POST">
<input type="button" value="0" name="zero">
</form>
<?php
if (isset($_POST["zero"]))
{
echo $_POST["zero"];
}
?>
Only an input[type=submit] will submit the form onclick. It is valid to have multiple submit buttons:
<form action="" method="POST">
<input type="submit" value="0" name="mybutton">
<input type="submit" value="1" name="mybutton">
<input type="submit" value="2" name="mybutton">
</form>
<?php
if (isset($_POST["mybutton"]))
{
echo $_POST["mybutton"];
}
?>
If you want to use input[type=button] then you will need some Javascript to trigger the submit, and a hidden input to transport the value.
<script>
window.onload = function(){
document.getElementsByName("mybutton").onclick = function(){
document.getElementsByName("postvar")[0].value = this.value;
document.forms.myform.submit();
}
};
</script>
<form name="myform" action="" method="POST">
<input type="hidden" name="postvar" value="" />
<input type="button" value="0" name="mybutton">
<input type="button" value="1" name="mybutton">
<input type="button" value="2" name="mybutton">
</form>
<?php
if (isset($_POST["postvar"]))
{
echo $_POST["postvar"];
}
?>
Change
<input type="button" value="0" name="zero">
To
<input type="submit" value="0" name="zero" />
Add an event handler if you want to do it via button click.
Try this
<form action="" method="POST">
<input type="submit" value="0" name="zero">
</form>
<?php
if (isset($_POST["zero"]))
{
echo $_POST["zero"];
}
?>
Use
<input type="submit" value="0" name="zero">
else if you want to use button use javascript
<form action="" method="POST">
<input type="button" value="0" name="zero">
</form>
<script type="text/javascript">
$("input[type='button']").click(function(){
alert(this.value);
});
</script>
Problem: How to make an HTML Form call different php pages from the action based on what button is pushed?
The code below is the solution I have now, but I figure there must be a better way to do this then creating multiple forms on the page?
<html>
<body>
<form name="entry_form" action="entry_update_script.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="entry_id" value="">
<input type="hidden" name="entry_item_id" value="">
Truck/Railcar/Barge#:<input type="text" name="pro_number" value=""><br>
BOL #:<input type="text" name="bol" value=""><br>
<input type="submit" name="entry_submit" value="Add New Entry!">
</form>
<form name="entry_form_add" action="entry_view.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="entry_id" value="">
<input type="submit" name="submit" value="Add New Item!">
</form>
</body>
</html>
<html>
<body>
<script type="text/javascript">
function submitAction(act) {
document.sample.action = act;
document.sample.submit();
}
</script>
<form name ="sample" action="default.php">
<input type="button" value = "blah1" onClick="submitAction('phpPage1.php')">
<input type="button" value = "blah2" onClick="submitAction('phpPage2.php')">
</form>
</body>
</html>
you might choose the page to go from a dispatcher, it's an extensible and robust solution:
your form
<form action="dispatcher.php" method="POST">
<input type="radio" name="myOption" value="register" />
<input type="radio" name="myOption" value="login" />
</form>
dispatcher.php
$actions = array ('register', 'login');
// validate possible actions
if (in_array($_POST['myOption']), $actions)) {
include ($_POST['myOption'] . '.php');
}