Jump to content

VERY simple php flowchart


Hamma

Recommended Posts

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...

 

 

Link to comment
https://forums.phpfreaks.com/topic/282373-very-simple-php-flowchart/
Share on other sites

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.

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;
  }

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.