stupid girl! Posted November 15, 2007 Share Posted November 15, 2007 Hi All I am trying to build a questionnaire that once submitted returns a page that will provide answers and products dependent on wha the response of the individual is. does my form have to be a get rather than post (im presuming it does). and how do i sort the conditions so that if one answer is selected it writes a unique response? thanks Quote Link to comment Share on other sites More sharing options...
axiom82 Posted November 15, 2007 Share Posted November 15, 2007 The Get Method is seen in the address bar and available in $_GET array after submitting the form. The Post Method is invisible and available in the $_POST array after submitting the form. Set the action of the form to be the page that will use the values of the $_POST array. Quote Link to comment Share on other sites More sharing options...
stupid girl! Posted November 15, 2007 Author Share Posted November 15, 2007 thanks was just looking into it and yeah post is the best option. so i post the info to the page, and are the conditions similar to those in javascript? Quote Link to comment Share on other sites More sharing options...
axiom82 Posted November 15, 2007 Share Posted November 15, 2007 Yes. I usually double-quote my strings when inserting array variables, even standard variables actually, and encapsulate with brackets to signify the insertion of a variable...like this... echo "Hello, {$_POST['name']}."; if you hate the brackets, you can remove the internal single quotes from the $_POST array key like this... echo "Hello, $_POST[name]."; Quote Link to comment Share on other sites More sharing options...
stupid girl! Posted November 15, 2007 Author Share Posted November 15, 2007 yeah added something like that in already! good to know im on the right lines lol basically ill give you an example. one of my form inputs is the following: <select name="mattbudget" id="mattbudget"> <option value="under100">Under £100</option> <option value="100-500">£100-£500</option> <option value="501plus">£501 plus</option> <option value="Please Select One" selected="selected">Please Select One</option> </select> so i want the php to write a response dependent on the option selected Quote Link to comment Share on other sites More sharing options...
axiom82 Posted November 15, 2007 Share Posted November 15, 2007 Form Code: <form action="response-generator.php" method="post"> <select name="mattbudget" id="mattbudget"> <option value="under100">Under £100</option> <option value="100-500">£100-£500</option> <option value="501plus">£501 plus</option> <option value="Please Select One" selected="selected">Please Select One</option> </select> </form> Response-Generator.php Code: // Only when content is posted, do this... // if (!empty ($_POST)){ if ($_POST['mattbudget'] == '100-500'){ echo 'Matt has a good budget.'; } } For multiple responses, populate a variable and echo it at the finish like this... // Only when content is posted, do this... // if (!empty ($_POST)){ $string = ''; if ($_POST['mattbudget'] == '100-500'){ $string .= 'Matt has a good budget.<br>'; } if ($_POST['matttaxes'] > 1000){ $string .= 'Matt has a good tax return.'; } echo $string; } Quote Link to comment Share on other sites More sharing options...
stupid girl! Posted November 15, 2007 Author Share Posted November 15, 2007 your an absolute legend thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.