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

Input Validation


  1. christopherbrooks
    Member

    Is it possible to add validation for a dropdown element, such that the default choice (eg, --select ...--) is NOT valid, but any other choice is valid? I want to force the user to make a selection.

    Posted 13 years ago #
  2. redityo

    This possible with small customization, edit your "includes/post-functions.php" file and go to around line 661 ~ 663 for these code :

    if($validation_result !== true){
    	$error_elements[$element_data] = $validation_result;
    }

    then put these code bellow those line

    $query = "select <code>option</code> from <code>ap_element_options</code> where form_id='$form_id' and option_id = '$element_data' and element_id = '$element_id' ";
    $result = do_query($query);
    $row = do_fetch_result($result);
    
    if ($row['option'] == "--select ...--") {
    	$error_elements[$element_data] = "You need to select another options";
    }

    make sure the option text is same with the one on your drop down (case sensitive)

    PS : change and in those code with backticks


    MachForm Support

    Posted 13 years ago #
  3. christopherbrooks
    Member

    Thank you for the suggestion. Can you clarify, I do not understand what you mean by:
    change and in those code with backticks

    Posted 13 years ago #
  4. christopherbrooks
    Member

    With some adjustment I am able to correctly test whether the drop down selection was the default (--Please select-- ) or something else. If default, you get an error when trying to continue, and if not, no error. However, the error is showing up on the last field of the form, not the field with the drop down default. So some further adjustment is apparently needed to get the error message to position on the correct field.

    Posted 13 years ago #
  5. christopherbrooks
    Member

    Got it! needed to use $error_elements[$element_id] rather than $error_elements[$element_data]

    Posted 13 years ago #

RSS feed for this topic

Reply