954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Form outcome option

I need to create a form where you have two possible finishing pages dependent on the answers you give in the form.

For instance if you have the question:

Do you like sweets?

And have the two possible outcomes

Yes or No

The answer yes takes you to a yesilikesweets.php or if you answer no when you hit submit
it takes you to noihatesweets.php

Any help greatly received.

cambraydesign
Newbie Poster
7 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
<?php
// one way 
if($_POST['sweets']){
	if($_POST['sweets'] == "yes"){
		header( 'Location: ../ilikesweets.php' )
		
	}ELSE{
		header( 'Location: ../idontlikesweets.php' )
		
	}
}

echo "<form method=\"post\" target=\"_self\" >
do you like sweets</br>
<select name='sweets' size=\"1\">
	<option></option>
	<option value=\"yes\">yes</option>
	<option value=\"no\">no</option>
</select>
<input type=\"submit\" />
</form>"

?>


<?php
// another way
if($_POST['sweets']){
	if($_POST['sweets'] == "yes"){
	include "ilikesweets.php";
		
	}ELSE{
	include "idontlikesweets.php";
		
	}
}ELSE{

echo "<form method=\"post\" target=\"_self\" >
do you like sweets</br>
<select name='sweets' size=\"1\">
	<option></option>
	<option value=\"yes\">yes</option>
	<option value=\"no\">no</option>
</select>
<input type=\"submit\" />
</form>"
}

?>
HITMANOF44th
Posting Whiz in Training
283 posts since Apr 2009
Reputation Points: 24
Solved Threads: 33
 

Nice one!! I'll give that a go, thanks for your prompt reply!! Legend

cambraydesign
Newbie Poster
7 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: