Appnitro Software Forums » MachForm

Select field Required

(5 posts)

  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 2 years ago #
  2. 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?

    Posted 2 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 1 year ago #
  4. 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;
    	}
    }
    Posted 1 year ago #
  5. franki
    Member

    That did it, thanks!

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.