How can i validate a select option data?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mary Meer

    #1

    How can i validate a select option data?

    I have select option $titles=array(' select ','Mr','Miss',' Mrs');
    Code:
    if(isset($_POST[$v[1]] )){
    		$initvalue=$_POST[$v[1]];
    			}else{$initvalue='';}
    echo '<td><select name ="titl">'."\n";
    	foreach($titl as $value){
    echo '<option value="'.$initvalue .'">' . $value .'</option>'."\n";}
     if(!isset($_POST['titl'])){
       $errormsg.='please select your title.';}
    echo'</select></td>'."\n";
    the default value is (select)if i dont change the title from select into Mr or Mrs and click on submit button i get the default value which is Select then i should have error message but it does not occur. Can anyone help?
    Last edited by Dormilich; Nov 23 '10, 02:17 PM. Reason: please use [CODE] [/CODE] tags when posting code
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Code:
    if(!isset($_POST['titl'])){
    But your select box IS set.
    Do you mean to test
    Code:
    if($_POST['titl'] == 'Select'){

    Comment

    • Mary meer

      #3
      yea but if it is not set eg. i have the defualt value which is (please select title) then still i am not having the error message.

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        yea but if it is not set
        It is set - ALWAYS, if the form has been submitted. As stated in my previous post, you are making the wrong test

        Comment

        Working...