Handling Remote Variables with Periods in Their Names

When dots (.) and spaces are used in the names of the input fields, PHP will replace them with an underscore to make them valid PHP variable names.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>
<title>PHP</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
function display_form() {
echo <<<HTML
<form action = "$_SERVER[SCRIPT_NAME]" method="post">
First name: <input type="text" name="first.name"><br />
Last name: <input type="text" name="last name"><br />
Phone: <input type="text" name="%phone"><br />
<input type="submit" name="submit" value="submit" />
</form>
HTML;
}

// check for submit button
if (isset($_POST['submit']))  {
	foreach ($_POST as $key =>$values) {
		echo $key, "=>", $values, '<br />';
	}
}
else {
	display_form();
}
?>
</p>
</body>
</html>

View the effect


Forms | Introduction | Creating a Form | Superglobals | Processing Form Input | Required Fields | Numbers | Drop-Down Menus | Radio Buttons | Checkboxes | Periods in Their Names | Preventing Cross-Site Scripting | Stripping out Slashes | Redirecting the User | Server Information | Determining Browser Type | Sticky Forms
© 2008: Hann So
email: hso@voyager.deanza.edu