hahn Posted July 2, 2009 Share Posted July 2, 2009 Hi all, I'm a noob in the world of php. Wonder if anybody here can help me with what I'm working on. What I'm trying to do here is to make a survey using checkbox and php and save the result into a text file. The survey is made of 5 pages, each containing multiple checkboxes and submit button. The structure for all 5 pages all exactly the same. So the expected user topography is like this. In page1.html, when user checks all that has to be checked and click submit, the page saves the result into a text file through PHP and redirect user to the page2.html In page2.html to page4.html exactly the same pattern goes here. When all the survey is complete page4 leads users to page5.html that gives the user "thank you message" Simple. So what I've tried to achive this is like this; page1.html here: <form onsubmit="window.open ('page2.html')" id="form1" name="form1" method="post" action="chi.php"> <input type="checkbox" name="chi[]" id="0" value="SYS" /> <input type="checkbox" name="chi[]" id="1" value="IMT" /> <input type="checkbox" name="chi[]" id="2" value="GOO" /> <input type="checkbox" name="chi[]" id="4" value="LEC" /> <input type="checkbox" name="chi[]" id="5" value="TRC" /> <input type="submit" name="submit" id="submit" value="Continue" /> 1. I'm using onsubmit="window.open ('[next_page.html]') here but wonder is there any better way to do the same job as it opens a new tab instead of printing the next page in the same tab. chi.php here: <?php $file = "chi.txt" if (isset($_POST)) { $fp = fopen($file, "a") or die("Couldn't open $file for login!"); $array = $_POST["chi"]; for ($i = 0; $i < count($array); $i++) { fwrite($fp, "$array[$i]\n\r"); } fclose($fp); } else { echo("No choice made."); } ?> The result I'm expecting from this code is like this; chi.txt SYS IMT GOO LEC LEC GOO ... ... I'll sort it up with excel later on. But for some reason it returns no result. Please help me finding out what's wrong on the both of codes above or suggest me with the better solution. Ciao! Han Link to comment https://forums.phpfreaks.com/topic/164493-making-survey-with-form-checkbox-using-php/ Share on other sites More sharing options...
Bendude14 Posted July 2, 2009 Share Posted July 2, 2009 have you tried a print_r($_POST["chi"]); to see if the correct data is been stored in the POST array.... Link to comment https://forums.phpfreaks.com/topic/164493-making-survey-with-form-checkbox-using-php/#findComment-867747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.