Reputation: 3230
I have a simple form which passes the value of an <input />
element:
<form action="updaterow.php" method="POST">
<input type="text" name="price" />
</form>
How can I post extra values along with the <input />
value? For example, an arbitrary string, or a variable inside the current PHP script.
I know this is possible with GET:
<form action="updaterow.php?foo=bar" method="GET">
<input type="text" name="price" />
</form>
or:
<form action="updaterow.php?foo=<?=htmlspecialchars($bar)?>" method="GET">
<input type="text" name="price" />
</form>
but I need POST.
Upvotes: 17
Views: 21832
Reputation: 91734
As mentioned already, using hidden input fields is an option, but you can also use a session. That way you don´t have to post anything, the variables remain on the server and are not exposed in the html.
Upvotes: 4
Reputation: 58962
You can simply use a hidden field. Like so:
<input type="hidden" name="your-field-name" value="your-field-value" />
This field will then be available in your PHP script as $_POST['your-field-name']
Upvotes: 10
Reputation: 131978
You can include a hidden form element.
<input type="hidden" name="foo" value="bar" />
Upvotes: 42