+ 2
How do you write php code for a form that only contains options and check boxes?
when this form is submitted results are supposed to be displayed on an html page. php is needed to take the answer in combination and give back a result. and I need help. I am stuck. anyone who could help pls make suggestions
2 Réponses
+ 1
<input type="checkbox" name="checkList[]" value="Yellow">
<input type="checkbox" name="checkList[]" value="Red">
<input type="checkbox" name="checkList[]" value="Blue">
^That'll store it as an array in checkList.
if(isset($_POST['checkList'])) {
foreach($_POST['checkList'] as $boxSelected) {
echo "<p>".$boxSelected."</p>";
}
}
Sorry man, I'm at work and have to leave so I couldn't finish. Hopefully this will get you pointed in the right direction. Basically, your selections will be stored in the $_POST data and you'll use that data to populate the area where you want to display the results. For options/checkboxes, it's easier to use an array and loop through the data to find out which were selected.
Best of luck! I'll check back when I get home in an hour or two if you need more help.
+ 1
For check box you can store the form element in a variable and then can use for each loop to iterate through all the checked elements and for options you can store that firm element and can then simply apply isset() to check whether it exists or not before printing.