Page 1 of 1

Trouble w/ single page form

Posted: Sat Nov 13, 2010 12:03 pm
by someguyhere
I know I must be missing something simple here...but this form never passes the input from the field, so it always shows the form rather than showing as done. What am I missing?

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

<?php
if (isset($field)) {

?>
	<p>Done</p>
</body>
</html>

<?php
die();
}

else

?>

	<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST" >
	<input type="text" name="field" />
	<input type="submit" value="Submit" />
	</form>
	<?php echo $field ?>
</body>
</html>

Re: Trouble w/ single page form

Posted: Sat Nov 13, 2010 12:34 pm
by requinix
For method=post forms you need to use the $_POST superglobal.

Code: Select all

<?php
if (isset($_POST["field"])) {

?>
        <p>Done</p>
</body>
</html>

<?php
die();
}
Read

Re: Trouble w/ single page form

Posted: Sat Nov 13, 2010 2:33 pm
by someguyhere
Perfect! Thank you!