tags:

views:

67

answers:

4

is there a way to create custom post variables when a user presses submit, like this:

$_POST['var'] = 'hi';
+5  A: 

In order to set post values on the page with the form you should use hidden input tags.

i.e.

<input type="hidden" name="var" value="hi" />

It will be invisible and your receiving script will see that key/value passed along.

RenderIn
+1  A: 

Variables POSTed by the browser to your PHP script will only correspond to the fields of the form that was used in the browser -- which means you have to put your custom data in that form.


If you don't want them displayed, you can use a hidden input field :

<input type="hidden" name="var" value="hi" />

But note that the data will still be sent by the browser -- which means you have to escape/filter/protect it, like any other value that comes from the user ; and it cannot be trusted : anyone can pretty easily modify the value of that form field, even if it's not visible.

Pascal MARTIN
+1 for pointing out that _anything_ from the browser should be considered tampered with.
Carson Myers
A: 

got it with hidden

phillip morris
A: 

while $_POST variable is an array, you can also define var like this

$_POST['var'] = 'hi';

it is same like hidden field. :)

apis17