PHP HTML HiddenField
From w3cyberlearnings
Contents |
HTML input tag with the type hidden is very important for passing information from and to the web page.
<input type="hidden" name="name" value="the value"/>
Note
Hidden field does not display on a web browser, but its value can be discovered by viewing the HTML source. It is a very bad idea to pass password or any important information through the hidden field.
Example 1
<?php if ($_POST) { print_r($_POST); } ?> <html> <head> <title>Hidden Field</title> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <table border="0"> <tr><td>Name:</td><td><input type="text" name="name" size="20"/></td></tr> <tr><td>Country:</td><td><input type="text" name="country" size="30" /></td></tr> <tr><td colspan="2"><input type="submit" value="submit" /></td></tr> </table> <input type="hidden" name="special_code" value="4762043656x42yJe245" /> </form> </body> </html>
Output
Example 2
<?php // process user input if (!empty($_POST['name']) && !empty($_POST['country'])) { $greeting = "Hello! " . ucfirst($_POST['name']) . ', you are from ' . ucfirst($_POST['country']); $greeting .= ', your special code is (hidden field) ' . $_POST['special_code']; } else { $greeting = 'please enter your name and your home country!<br/>'; } ?> <html> <head> <title>Hidden Field</title> </head> <body> <b><?php echo $greeting; ?></b> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <table border="0"> <tr><td>Name:</td><td><input type="text" name="name" size="20"/></td></tr> <tr><td>Country:</td><td><input type="text" name="country" size="30" /></td></tr> <tr><td colspan="2"><input type="submit" value="submit" /></td></tr> </table> <input type="hidden" name="special_code" value="4762043656x42yJe245" /> </form> </body> </html>
Output
Related Links
- HTML Hidden Field
- HiddenField Multiple Pages
- HTML Password