This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Select field Required


  1. MikeBWD
    Member

    Hi All
    By default you get (without setting default)
    '<option value="" selected="selected"></option>'
    and have an empty field just
    change to:
    '<option value="1" selected="selected">Please select</option>'
    (by setting default) and client can submit the form with "Please select" selected

    is there a work around for this?
    thanks Mike

    Posted 16 years ago #
  2. yuniar

    Let me clarify this.

    So you would like to have a select/drop down field, set as required and the default value is "Please select", but client shouldn't be able to submit "Please select".

    Am I correct?


    MachForm Founder

    Posted 16 years ago #
  3. franki
    Member

    Hi Yuniar, I'll finish this post...
    I'm in the same predicament. As you described, I have a drop down field which is populated with email addresses and is required. For my default I have "Please select". If I submit the form with "Please select" in the field there are no indications that this field needs attention. It would be ideal if the form sees that this default text is not an email address and thus error.

    Thanks!

    Posted 16 years ago #
  4. redityo

    Hi,

    You can modifiy "includes/common-validator.php" file to add some validation. I assume your "please select" text located on first value of "Drop down element", so it will have value = "1".

    Now search around line 30 ~ 39 on "includes/common-validator.php" file, you'll find these code :

    function validate_required($value){
    
    	$value = $value[0]; 
    
    	if(empty($value) && (($value != 0) || ($value != '0')))  ){ //0  and '0' should not considered as empty
    		return VAL_REQUIRED;
    	}else{
    		return true;
    	}
    }

    replace with this one

    function validate_required($value){
    
    	$value = $value[0]; 
    
    	if((empty($value) && (($value != 0) || ($value != '0'))) || ($value == '1') ){ //0  and '0' should not considered as empty
    		return VAL_REQUIRED;
    	}else{
    		return true;
    	}
    }

    MachForm Support

    Posted 16 years ago #
  5. franki
    Member

    That did it, thanks!

    Posted 16 years ago #

RSS feed for this topic

Reply