Hamma Posted September 23, 2013 Share Posted September 23, 2013 Hi all. I'm just learning php. Familiar with some basic stuff, enough to want to do something a little more complex than the examples out of the books I'm using. This is my first attempt at a project. I want to make a help file based on forms - simple questions in the form, radio button selections, and then serve up the next form (or page) from the result. I know this has to be simple, I just can't seem to get it to work right. Before I pester this forum needlessly with my no doubt horrific code example, is there a simple example somewhere that someone could point me at? I'll be happy to let you see the code I'm trying to hammer out, if you like. I won't be offended if you you tell me I'm way out in lef field... Quote Link to comment Share on other sites More sharing options...
Hamma Posted September 23, 2013 Author Share Posted September 23, 2013 OK! After banging my head against the keyboard this morning, and manipulating the examples I have, you can see what I'm working with at the moment: http://webdissemble.com/indexradonly.php Help would be greatly appreciated!!! I'm a technical writer by trade, and know HTML and CSS. LIke I said, PHP is new to me. Quote Link to comment Share on other sites More sharing options...
Solution Hamma Posted September 24, 2013 Author Solution Share Posted September 24, 2013 I figured it out, and it was exceedingly simple. I evaluated the contents of the POST array and sent a new header string. In case anyone else has a similar noob issue, here's the code that worked, it's only of interest to rank beginners. But if anyone else reads this and has experience putting together flow chart style forms, I wouldn't turn away any suggestion for alternative methods, I'm sure there are many. // evaluate the answer if ($_POST && $_POST['subscribe'] == 'Yes') { header('Location: http://www.webdissemble.com/yes.php'); exit; } if ($_POST && $_POST['subscribe'] == 'No') { header('Location: http://www.webdissemble.com/no.php'); exit; } Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted September 24, 2013 Share Posted September 24, 2013 For what it's worth, the code would be more efficient if you used an elseif. Also note that I used isset() to make sure the "subscribe" variable is set before performing the test. <?php // evaluate the answer if(isset($_POST['subscribe']) && $_POST['subscribe'] == 'Yes') { header('Location: http://www.webdissemble.com/yes.php'); exit; } elseif(isset($_POST['subscribe']) && $_POST['subscribe'] == 'No') { header('Location: http://www.webdissemble.com/no.php'); exit; } ?> You could also simplify the code as follows: <?php // evaluate the answer if(isset($_POST['subscribe'])) { if($_POST['subscribe'] == 'Yes') { header('Location: http://www.webdissemble.com/yes.php'); exit; } elseif($_POST['subscribe'] == 'No') { header('Location: http://www.webdissemble.com/no.php'); exit; } } ?> Note that I marked the topic as solved. If you need further assistance, please mark it as unsolved or start a new topic. 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.