Menu

Required field, dropdown menu, default option

Help
2006-07-10
2013-06-03
  • ilterocktive

    ilterocktive - 2006-07-10

    Hi guys.
    I use this script happily, but 1 problem remains.
    I have some required fields as dropdown menus, and if person who enters/chooses data skipps these dropdown menus, the result always shows the 1st default text in the menu.
    I can try to enter an empty field, or a field which says: "Choose", but still its not a permanent solution. I don't want to see many "Choose" as a form result anyway :)
    I have some html and php "editing" experience, so if you can point me out a way, it would be well appreciated.
    Cheers!

     
    • ilterocktive

      ilterocktive - 2006-07-18

      In html (i.e."form1.html"), add OR edit this line of code:

      <select name='choose'>
      <option value='default' selected='selected'>Please choose</option>
      <option value='Option1'>Option 1</option>
      <option value='Option2'>Option 2</option>
      <option value='Option3'>Option 3</option>
      </select>

      ...AND for the php process file (i.e."process.php"), add OR edit this line of code:

      if($choose=="default" ){
      $errors=1;
      $error.="<li>"You didn't enter/choose 1 of the required fields";
      }

      Now, if your dropdown menu option is a required field, you can be sure that user will not "miss" a required field without choosing the options YOU have listed.

      PS1. "choose" and "Option 1...2...3" are given as an example text. You should write the field names and Options the way you want.
      PS2. There can be alternative solutions to it, but this 1 felt handy/easy to me. And most importantly, it works... :)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.