Jump to: navigation, search

PHP HTML HiddenField

From w3cyberlearnings

Contents

PHP works with HTML hidden field

HTML input tag with the type hidden is very important for passing information from and to the web page.

Syntax hidden

<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

Php form hidden 1.png

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

Php form hidden 2.png

Related Links


  1. HTML POST
  2. HTML GET
  3. HTML Textarea
  1. HTML Hidden Field
  2. HiddenField Multiple Pages
  3. HTML Password
  1. HTML Textbox
  2. HTML Checkbox
  3. HTML Radio
  1. Drop down list
  2. Pass value uses URL
  3. Pass value uses URL 2.
  4. Multiple Submit Buttons
Navigation
Web
SQL
MISC
References