Re: Two forms on one page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear List -

I would like to have two(2) forms in one PHP script. I would like to have the forms appear sequentially; ie, that the first form would appear, the data would be entered, and then the second form would appear, the data would be entered, and the script would exit.

The code below displays both forms simultaneously. After the data is entered for the first form, the second form appears again. After the data is entered for the second form, the script displays the statement "" from the first form.

Would you please help me correct the script so that it will perform as required.

Thanks.

Hi Ethan,

did you read my post to you on Friday?

If you want to fix your code, you'll have to scrutinize it, carefully, line by line. Read docs, and stare at every line until you understand what it is doing. It is not very coherent.. but at the least, it looks to me that, this:
if ( !isset($_POST['cat'])) //&& $_POST['submit'] === 'Submit Kitten' )
{
echo <<<HTML
       <form method="post" onsubmit="catdo();">
       Enter your kitten's name: <br />
       <input type="text" name="cat" />
       <input type="submit" name="submit" value="Submit Kitten" />
       </form>
HTML;
}

..will fire every time $_POST['cat'] is not set... and that is at the beginning, *AND* after the 1st form is submit, right? If you do not want that to fire when user first comes in, then you have to change that code line's logic.

..meanwhile...

I had imagined you starting over with something coherent and bare- bones.. like: (upload this and try it out... then fill it out with your real code... if you like.)

---------------------------------------------------------------------------------------------------------------------------
<!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"; xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>Untitled</title>
	<meta name="generator" content="BBEdit 9.6" />
</head>
<body>

<?php
switch ($_POST['submit']) {
case "Submit": // 1st form was submitted.. so do stuff and then show the 2nd form:
		//do stuff (omitted here for clarity to show just the flow of logic)
		echo "this is form # 2<br />";
		echo "<form method=\"post\">";
		echo "Enter your cat's name: <br />";
		echo "<input type=\"text\" name=\"cat\" />";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit Kitten \" />";
		echo "</form>";
	    	break;
case "Submit Kitten": // 2nd form was submitted.. so do stuff and then show stuff:
		//do stuff (omitted here for clarity to show just the flow of logic)
		$name_cat = htmlspecialchars($_POST['cat']);
		echo "Your Kitten is $name_cat";
		break;
	default: // show the 1st form:
		echo "this is form # 1<br />";
		echo "<form method=\"post\">";
		echo "Enter your date of birth, in mm/dd/yyyy format: <br />";
		echo "<input type=\"text\" name=\"dob\" />";
		echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />";
		echo "</form>";
		break;
}
?>

</body>
</html>
---------------------------------------------------------------------------------------------------------------------------

-Govinda

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux