Jump to content

Recommended Posts

Posted

Hi all

 

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") ?>");

return false;

}

 

Modification 2 I have made in edit_entry.php

 

<?php

for ($c = "A"; $c <= "A"; $c++)

 

 

 

{

if (!empty($typel2[$c]))

{

echo " \n";

}

}

 

 

for ($c = "B"; $c <= "Z"; $c++)

{

if (!empty($typel[$c]))

{

echo " \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.

 

Thanks

 

J

mrbs.jpg

mrbs1.jpg

mrbs2.jpg

Posted

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.

 

What you have popped up on the thumbnail (the first one) is a Javascript Alert box (I think !). This is a Javascript function, not a PHP one, and whilst you can theoretically do this by outputting script in PHP this is a strange way of doing it. If you want alert() boxes (Javascript message box) then you should be client side validating your form in Javascript before it is Posted back to the server. If you google there are plenty of articles on client-side validation.

 

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.

Posted (edited)

a quick thinkup php side goes somthing like this! presuming your passing information with the POST method?

 

$deptcheck = $_POST["<>"];

if $deptcheck == "Please Select your Department"

<>

 

Those 3 lines (as you have "Please Select your Department" as default) checks the information submitted to the <> field, to see if it matches, and if it does then it would mean that the user has not selected another option.

 

must admit though it would be usefull to validate it with javascript, as it saves strain on the server that way too. unfortunatly javascript i'm not too familiar with on that one, you would need to do some googleing ^_^

 

Regards

 

Koryo

Edited by koryo
  • 3 weeks later...
Posted

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

JQuery dropdown.jpg

  • 1 month later...
Posted

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)

 

hth

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...