We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17459
    • 268 Posts
    <?php
    function eFormOnValidate( &$fields, &$vMsg, &$rMsg ){
    	/*
    		&$fields - (as reference) an associative array of field and placeholder values.
    		&$vMsg - (as reference) a numeric array of validation error messages.
    		&$rMsg - (as Reference) a numeric array of missing required fields.
    	*/
    		if($fields['email'] !== $fields['myconfirmemailaddress']) $vMsg[15] = "Different values in Email and Confirm Email fields";
    		return $vMsg;
    	}
    ?>

                    <tr>
                      <td height="25" colspan="4">Email Address</td>
                    </tr>
                    <tr>
                      <td colspan="4"><input name="email" type="text" id="Email" size="35"  eform="Email:email:1:"></td>
                    </tr>
                    <tr>
                      <td height="25" colspan="4">Confirm Email Address </td>
                    </tr>
                    <tr>
                      <td height="25" colspan="4"><input name="myconfirmemailaddress" type="text" id="Confirm Email" size="35"  eform="Confirm Email:email:1::#FUNCTION eFormOnValidate"></td>
                    </tr>


    if I submit form with first field: Email: [email protected], Confirm Email: (nothing), I get error msg from $vMsg[15].
    If I submit form with [email protected]/[email protected] or [email protected]/[email protected] or (nothing)/[email protected], i see

    « MODx Parse Error »

    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »

    PHP error debug
      Error: Missing argument 2 for eformonvalidate()
      Error type/ Nr.: Warning - 2
      File: ***********/manager/includes/document.parser.class.inc.php(769) : eval()’d code
      Line: 2
      • 23491 ☆ A M B ☆
      • 1,056 Posts
      I’ve used this in the past, and I generally append the field name to $rMsg and simply "return" from the validation function.

      Try this and let us know if it works:

      <?php
      function eFormOnValidate( &$fields, &$vMsg, &$rMsg ){
      		if($fields['email'] !== $fields['myconfirmemailaddress']) {
      		    $rMsg[] = 'email'; // Required field
      		    $vMsg[] = "Different values in Email and Confirm Email fields"; // Associated validation message
      		}
      		return;
      	}
      ?>



      Hope that helps! cool
        Mike Reid - www.pixelchutes.com
        MODx Ambassador / Contributor
        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
        ________________________________
        Where every pixel matters.
        • 30223
        • 1,010 Posts
        You are confusing the eformOnvalidate event with the #FUNCTION .. validation rule.
        #FUNCTION - Name of a function. The function should expect one parameter (the posted value) and return either TRUE or FALSE.

        In your case you want to compare 2 fields, which you can’t do in a #FUNCTION rule, so scrap the "#FUNCTION eFormOnValidate" bit in your form and replace it with
        <input name="myconfirmemailaddress" type="text" id="Confirm Email" size="35"  eform="Confirm Email:email:1">


        Then use your validate function in the eformOnValidate event:
        [!eForm? ... &eformOnValidate=`eFormOnValidate` ... !]
        


        The eformOnvalidate event is fired when all of eform’s native validation has finished. As far a I can see so quickly your function should then simply work, although I’d replace $vMsg[15]="..." with $vMsg[]="..."