Trouble w/ single page form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Trouble w/ single page form

Post 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>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Trouble w/ single page form

Post 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
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Trouble w/ single page form

Post by someguyhere »

Perfect! Thank you!
Post Reply