Sending additional $_POST data?
I use a form to send some data to my welcome.php file:
<form action="welcome.php" method="post">
Name: <input type="text" name="txt" />
<input type="submit" />
</form>
But, is it possible to send other variables instead of just form element values? Let's say I want to send the num开发者_如何学编程ber 100 to welcome.php as well.
You would probably use a hidden input:
<form action="welcome.php" method="post">
<input type="hidden" name="myNumber" value="100" />
Name: <input type="text" name="txt" />
<input type="submit" />
</form>
That would send the myNumber $_POST value to welcome.php.
Modifying the action like this: welcome.php?myNumber=100
would mean that you are sending a GET variable in addition to the POST variables inside the form.
NOTE: You could theoretically use both, but I believe that would only put the $_POST value in the $_REQUEST object. You should confirm that before relying on that behavior.
If I understand correctly:
<input type="hidden" name="myNumber" value="100" />
Right?
other then hidden fields or form element you can use AJAX
to send other variables into the post.
where you can pass url with your new variables other than form fields.
Thanks.
You can hardcode that into your action:
<form action="welcome.php?number=100" method="post">
This should work:
<form action="welcome.php?number=100" method="post"/>
or use a hidden form input
<input type="hidden" name="number" value="100" />
You can use html hidden field or store the value what you want in session or cookie varible
精彩评论