drop down menu in php
I was wondering if somebody could help me with a bit of code, we are currently using mrbs and I have a bit of an issue with it at the moment when staff book a room they are not selecting there department and just leave it as default, the default entry is A in a list array which I have set to please select your department.
what I want to do is to force the them to select any entry apart from default by throwing up an error if not selected I have managed to get as far as getting the error on screen but I unable to link it with the entry type.
please see attached jpegs
Modification 1 I have made in edit_entry.php
<?php if ($type2 == "$c")?>
alert ( "<?php echo get_vocab("you_have_not_selected") . '\n' . get_vocab("your_department") ?>");
Modification 2 I have made in edit_entry.php
<label for="type"><?php echo get_vocab("type")?>:</label>
<select id="type" name="type" id="type2 name "type2">
for ($c = "A"; $c <= "A"; $c++)
echo " <option value=\"$c\"" . ($type2 == $c ? " selected=\"selected\"" : "") . ">$typel2[$c]</option>\n";
for ($c = "B"; $c <= "Z"; $c++)
echo " <option value=\"$c\"" . ($type == $c ? " selected=\"selected\"" : "") . ">$typel[$c]</option>\n";
Modification 2 I have made in config.inc.php
$typel2["A"] = "Please Select your Department";
$typel["B"] = "Admin";
$typel["C"] = "Art";
$typel["D"] = "Careers";
$typel["E"] = "Child Development";
$typel["F"] = "Citizenship&RE";
$typel["G"] = "Diploma";
$typel["H"] = "Drama";
$typel["I"] = "English";
$typel["J"] = "Geography";
$typel["K"] = "History";
$typel["L"] = "ICT&Business Studies";
$typel["M"] = "ICT-Support";
$typel["N"] = "Maths";
$typel["O"] = "Media";
$typel["P"] = "MFL";
$typel["Q"] = "Music";
$typel["R"] = "PE&Dance";
$typel["S"] = "Science";
$typel["T"] = "SEN";
$typel["U"] = "SLT";
$typel["V"] = "Technology";
$typel["W"] = "All Staff";
Has any body had any similar issues or know where I am going wrong with my coding.
As far as I can see your approach is fundamentally wrong. You want to output the same HTML each time, whatever you are doing. Then on your postback, validate the form (this would include checks on the combobox select, obviously).
If the validation(s) fail then you need to mark them somehow - for example have an red asterisk alongside those which are wrong, and reseed the HTML Form controls with the data, so they don't have to type it in again.
Don't assume this works however ; your server side PHP should still cope with bad values - even if it just throws an error if it gets a value that the validation says it shouldn't.
a quick thinkup php side goes somthing like this! presuming your passing information with the POST method?
$deptcheck = $_POST["<<INSERT FIELD NAME HERE>>"];
if $deptcheck == "Please Select your Department"
<<insert error / handle code here>>
Those 3 lines (as you have "Please Select your Department" as default) checks the information submitted to the <<INSERT FIELD NAME HERE>> field, to see if it matches, and if it does then it would mean that the user has not selected another option.
Thanks for your replies guys I appreciate it, So far I have managed to force the error please select your department by using a jquery script, but unfortunately I can only get it to work with a seperate save button.
I some how have to figure out how to link my script with the original save button.
Thanks for your replies guys, I have managed to do it now just by using a java script and a little modification in edit_entry.php with the drop down menu coding.
just a thought to add in. if this is part of a larger form, make sure your php feedback page carries valid form values over to the feedback page. if i fill in ten boxes then miss a drop down, i'd like the ten boxes to stay filled in or to be held in hidden inputs so i can just focus on correcting the dropdown. i guess you could rely on people clicking the back button but i've had that reset the form before (not sure if blanking the form was a browser thing or a "feature" of the page that had been coded in)