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.
Related
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>
I just learn html and css and I need to do a project that build a robot and control the robot using website.
When I click the button it will go to other page or reload
How do I pass the value in the button without reloading the page?
This is my code:
<!DOCTYPE html>
<html>
<head>
<title>RPOC</title>
</head>
<body>
<form action="welcome.php" method="post" type='submit'>
<button>FORWARD
<input type="hidden" name="value" value="1"><br></button>
</form>
<form action="welcome.php" method="post" type='submit'>
<button>BACKWARD
<input type="hidden" name="value" value="2"><br></button>
</form>
</body>
</html>
Your html contains a few mistakes. Try this:
<body>
<form action="welcome.php" method="post">
<input type="hidden" name="value" value="1">
<button type="submit">FORWARD</button>
</form>
<form action="welcome.php" method="post">
<input type="hidden" name="value" value="2">
<button type="submit">FORWARD</button>
</form>
</body>
Removed type="submit" from form element
Removed hidden input in button element
Added type="submit" to button element
Looks like you need a ajax call...
Try something like this, but you will have to make a ajax.page.php file.
You can learn more at: http://api.jquery.com/jquery.ajax/
$('#btoForward01').click(function(e){
var value01 = $('#value01').val();
var fullURL = "ajax.page.php?value01=" + value01;
//console.log(urlCompleta);
e.preventDefault();
$.ajax({
url: fullURL,
success: function(result){
console.log('evething alright');
},
statusCode: {
404: function(){alert( "Page not found" );},
500: function(){alert( "PHP Error" );}
}
});
});
<body>
<form action="welcome.php" method="post">
<input type="hidden" name="value" value="1" id="value01">
<button type="submit" id="btoForward01">FORWARD</button>
</form>
</body>
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 } ?>
index.php
<html>
<head>
<script type="text/javascript">
function submitForms()
{
document.forms["form-1"].submit();
document.forms["form-2"].submit();
}
</script>
</head>
<body>
<form method="POST" action="form.php" id='form-1'>
<input type="text" name="txt1" />
</form>
<form method="POST" action="form.php" id='form-2'>
<input type="text" name="txt2" />
</form>
<input type="button" value="Click Me!" onclick="submitForms();" />
</body>
</html>
form.php
<?php
echo $_POST['txt1'];
echo $_POST['txt2'];
?>
Above is my code and when i submit both forms then both text-fields with their value it does not shoe me both text-field values.It only shoe me second text-field value.Please help me quickly.
I think because you try to get the params after sumbit two forms. You have sent the two forms at once and the second has stepped to the first, so the result is the return of the second form.
I think this will be better:
<html>
<head>
</head>
<body>
<form method="POST" action="form.php">
<input type="text" name="txt1" />
<input type="text" name="txt2" />
<input type="submit" value="Click Me!" />
</form>
</body>
</html>
<?php
echo $_POST['txt1'];
echo $_POST['txt2'];
?>
Sorry for my english
I am trying to get user input from a text box and then echo it using php. Here is my code, and it is not seeming to work.
<html>
<body>
<?php
echo $_POST['value'];
?>
<form method="post" action="">
<input type="text" name="value">
<input type="submit">
</form>
</body>
</html>
<html>
<body>
<?php
if(!empty($_POST['value']))
{
echo filter_var($_POST['value'], FILTER_SANITIZE_STRING);}
?>
<form method="post" action="">
<input type="text" name="value">
<input type="submit">
</form>
</body>
</html>
First check if form posted.