Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php custom post variables

Tags:

post

php

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

$_POST['var'] = 'hi';
like image 980
phillip morris Avatar asked Sep 28 '26 06:09

phillip morris


2 Answers

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.

like image 98
aw crud Avatar answered Sep 29 '26 19:09

aw crud


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.

like image 36
Pascal MARTIN Avatar answered Sep 29 '26 19:09

Pascal MARTIN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!