jeudi 30 mars 2017

picking up checkbox value and displaying information based on what is checked in php

I am trying to create a system that displays a sport the user might want to play based on what they already play. The system will display the question "What sport do you play?" and give the user a number of options with checkboxes to choose the sports that they already play. When the user clicks the submit button the system will generate an answer based on what they have chosen. For example of the user picks basketball and rugby then the system will display football.

I have started by creating an array to store each value and display them in a checkboxes as shown below.

<?php
                $city = 'city';
                $options = array("Football","Basketball","Rugby", "Hocky", "Golf");
                $box = "";

                if(isset($_REQUEST["$city"])) {
                        $checked=$_REQUEST["$city"];
                }else{
                        $checked=array();
                }
                foreach ($options as $option) {
                        $checkmark=(in_array($option,$Checked))?'checked':'';
$cityAsArray=$city.'[]';

$boxs.=($style=='V')?"<span class='label2' align='right'><b>$option : </b></span>":"<b>$option </b>";
$boxs.="<input type='checkbox' name='$cityAsArray' id='$option' value='$option' $checkmark >";
}

                echo<<<EOF

<form name="Update" method="GET" action="{$_SERVER['PHP_SELF']}">\n


{$boxs}
<br>
<br>
<button type="submit" >Submit Form</button>
</form>
EOF
;

?>

I want to have a function that picks up what has been clicked and displays the right information based on that. I have searched online for tutorials to help with this but I am unable to find any.




Aucun commentaire:

Enregistrer un commentaire