Click to See Complete Forum and Search --> : Concerning the use of hidden in <input>


CanMike
06-14-2006, 12:52 PM
As I continue to learn HTML and PHP there is one thing I'd just do not understand. You create a <form>, build the various input types, 'text', 'password', etc and usually a 'submit' type. Then you build another input type of 'hidden', with accompanying name and value attributes.

In the PHP code you then issue an if (isset($_POST['name attribute'])), which checks the name attribute of the hidden type.

Why use the hidden attribute? You can just as easily use the name attribute of the submit type?

I'm I missing something here?

Charles
06-14-2006, 01:33 PM
Why use the hidden attribute?A hidden form control also has a value. You can use it to "save state" with a multi-page form. I use it to indicate that the form has been validated by JavaScript.

CanMike
06-14-2006, 01:50 PM
Thanks for taking the time to answer.

I kind of understand the concept of 'save state', but given two input statements:

<input type='submit' name='submit' value='Login' />
<input type='hidden' name='submitted' value='TRUE' />

my PHP code checks

if (isset($_POST['submitted'])){

$name1 = $_POST['submitted'];
$name2 = $_POST['submit'];

echo $name1; --> displays 'TRUE'
echo $name2; --> displays 'Login'

require_once('./includes/mysql_connect.php'); // Connect to db.
code continutes....


Isn't the 'save state' simply the value of $_POST variable?

felgall
06-14-2006, 03:08 PM
Normally hidden fields are used to contain values that are either created/changed by Javascript OR you have multiple instances of the form each of which has a different value for the hidden field so that you can tell which of the forms it was did the submission.

Also the submit button may not be passed with the form if the form is submitted without actually clicking on the button but by some other means. Only currently selected buttons are passed with the form.

CanMike
06-14-2006, 03:51 PM
OK, now I starting to get it. You can hold a value to be used, even if the button is not used.

kiwibrit
06-14-2006, 07:04 PM
I use it for a value brought forward from a previous page, and being carried on to the next, along with a value input from the present page, in php.

CanMike
06-14-2006, 07:11 PM
Now it all make sense.

See, us old Oracle DBA's, COBOL/Java/ & PL/SQL developers can learn new trick if you hit us over the head hard enough.

Thanks all

I say, bring back green screens!

ray326
06-14-2006, 10:57 PM
A web browser is just a 3270 with lipstick. Check out this form handler for a very common use of hidden fields.

http://www.bignosebird.com/carchive/bnbform.shtml

felgall
06-15-2006, 03:54 PM
A web browser is just a 3270 with lipstick.

Never thought about it quite that way before but I think that description is very accurate.