+ Post New Thread
Results 1 to 6 of 6
Coding Thread, drop down menu in php in Coding and Web Development; Hi all I was wondering if somebody could help me with a bit of code, we are currently using mrbs ...
  1. #1
    walkden-high's Avatar
    Join Date
    May 2009
    Location
    salford- manchester
    Posts
    29
    Thank Post
    6
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Post drop down menu in php

    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

    <div id="div_type">
    <label for="type"><?php echo get_vocab("type")?>:</label>
    <select id="type" name="type" id="type2 name "type2">
    <?php
    for ($c = "A"; $c <= "A"; $c++)



    {
    if (!empty($typel2[$c]))
    {
    echo " <option value=\"$c\"" . ($type2 == $c ? " selected=\"selected\"" : "") . ">$typel2[$c]</option>\n";
    }
    }


    for ($c = "B"; $c <= "Z"; $c++)
    {
    if (!empty($typel[$c]))
    {
    echo " <option value=\"$c\"" . ($type == $c ? " selected=\"selected\"" : "") . ">$typel[$c]</option>\n";
    }
    }

    ?>
    </select>
    </div>


    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
    Attached Images Attached Images

  2. #2

    Join Date
    Feb 2009
    Location
    Norfolk, England
    Posts
    12
    Thank Post
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    11
    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.

  3. #3

    Join Date
    May 2010
    Location
    England
    Posts
    104
    Thank Post
    20
    Thanked 16 Times in 13 Posts
    Rep Power
    11
    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.

    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
    Last edited by koryo; 25th June 2010 at 09:23 AM.

  4. #4
    walkden-high's Avatar
    Join Date
    May 2009
    Location
    salford- manchester
    Posts
    29
    Thank Post
    6
    Thanked 1 Time in 1 Post
    Rep Power
    0
    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
    Attached Images Attached Images

  5. #5
    walkden-high's Avatar
    Join Date
    May 2009
    Location
    salford- manchester
    Posts
    29
    Thank Post
    6
    Thanked 1 Time in 1 Post
    Rep Power
    0
    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.

  6. #6

    Join Date
    Aug 2010
    Location
    Leicestershire
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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

SHARE:
+ Post New Thread

Similar Threads

  1. Drop down menu alignment
    By elanalazar in forum EduGeek Joomla 1.5 Package
    Replies: 0
    Last Post: 4th November 2009, 08:02 PM
  2. Drop Down Menu Apple Style
    By neilmc in forum EduGeek Joomla 1.0 Package
    Replies: 0
    Last Post: 5th October 2009, 03:35 PM
  3. Drop down menus - extended menu
    By mossj in forum EduGeek Joomla 1.5 Package
    Replies: 1
    Last Post: 9th January 2009, 06:34 AM
  4. drop down list in a html webform and php
    By Uraken in forum Coding
    Replies: 17
    Last Post: 5th March 2008, 12:35 PM
  5. Create menu & sub-menu with Edugeek Joomla
    By FN-GM in forum EduGeek Joomla 1.0 Package
    Replies: 24
    Last Post: 8th December 2007, 11:48 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •