I have a form which allow users to choose the type of permit they wish to apply for. There are 3 types of permit class and 8 categories of permit type.
Please take a look at this screenshot for better understanding: https://i.stack.imgur.com/mRC9O.jpg
For the classes, users can only choose 1. but for the categories users can apply multiple or single.
Users can choose 2 categories but 0 classes. Likewise users can choose 1 class and 0 categories. But user must at least choose something out of the 11 options.
Eg. User apply for Class 1 only OR User apply for CAT 2TT and CAT 3PG.
The coding to my form:
<div class="contents">
<form id="applicationoptions" method="post" action="s_apply_now.php">
<div id="optionshead">Class :</div>
<div id="classoptions">
<input type="radio" name="class" value="1" /> Class 1 Permit
<input type="radio" name="class" value="2" /> Class 2 Permit
<input type="radio" name="class" value="3" /> Class 3 Permit
</div>
<div id="optionshead2">Categories :</div>
<div id="catoptions">
<input type="checkbox" name="cat" value="1" /> CAT 2PG
<input type="checkbox" name="cat" value="2" /> CAT 1OR
<input type="checkbox" name="cat" value="3" /> CAT 2TT <br/><br/>
<input type="checkbox" name="cat" value="4" /> CAT 3PG
<input type="checkbox" name="cat" value="5" /> CAT 2OR
<input type="checkbox" name="cat" value="6" /> CAT 3TT <br/><br/>
<input type="checkbox" name="cat" value="7" /> CAT 4PG
<input type="checkbox" name="cat" value="8" /> CAT 3OR
</div>
<div class="applynext">
<input class="applynextbutton" type="submit" name="applynextbutton" value="PROCEED" />
</div>
</form>
</div>
After user checked their selection, the system will then separate the selections and store them in the database.
The database schema:
permit (PID, EID, PTYPE, STATUS, MID, HRID)
If user did not choose anything, the system will alert them and ask them to choose something
If user choose more than 2 class, the system will warn alert them to choose only 1 class.
What do you guys think? Is PHP able to allow me to accomplish these intentions?
P.S.: Please tell me how can I make spaces without using too many &npsb;. Is there a way to change the radio button to checkbox and disable the multiple selection?
Guys…I have a problem…how do I in php to retrieve data from checkbox?? any example??
i tried array[] it but can’t seem to work..
Yes PHP will work. You can get the necessary data posted via the $_POST collection, and communicate with whatever database you’re using to store them.
For spacing, I suggest learning CSS and avoid adding lots of non-breaking spaces.
As far as handling the checkbox values, it looks like you want to allow the user to select multiple values corresponding to one name (class, and cat). As you have it, PHP will just end up with the last value they selected. You can modify the name of your form inputs to cause PHP to treat them like an array on the backend. Then when you grab $_POST[‘class’] you will get an array.
If both of those are checked by the user, you would see this in PHP
If they only checked one, you would have just one element in the array.
You can even make it an associative array if having keys in your array make it easier to handle the data:
and in PHP