We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38060
    • 29 Posts
    My form is asking information before sending the user to another page. I applied multiple field validations directly to the fields with #function. These validations work perfectly. The functions for that are stored in DownloadFormValidation.

    I addition to this I created the function validateZipAddress() where I want to perform a very simple address verification later on. But for now I just want to see if my function is getting triggered and if I can stop the form from transmitting by sending the error message.


    Which uses the information of multiple fields. I programmed the code for it, but it did not work. I stripped down the code just to see if I can get any control over

    [!DownloadFormLog!]
    [!DownloadFormValidation!]
    [!DownloadAddressValidation!]
    [!eForm? &noemail=`true` &formid=`downloadForm` &tpl=`DownloadFormHTML` &protectSubmit=`0` &gotoid=`[[DownloadId]]` &requiredClass=`requiredValue` &invalidClass=`invalidValue` &debug=`3` &eFormOnBeforeMailSent=`logDownload` eFormOnValidate=`validateZipAddress` !]


    -- snippet DownloadAddressValidation --


    function validateZipAddress(&$fields, &$vMsg, &$rMsg, &$rClass) {

    echo "come on show me this line!";

    $numberOfFields=count($fields);

    $vMsg[$numberOfFields] = "Address verification failed. Please enter a valid address.";

    return $vMsg;

    }


    -- / snippet DownloadAddressValidation --



    The problem is, that it does forward to the next page. Has anybody a clue what I am doing wrong?

    By the way, I also tried to return false instead of $vMsg, which did not work either.

    I was already googling for hours and hope that somebody can help me here with that issue.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I don't think you can specify more than one function for each event. Try including all the code you want executed for a given event in one function. You can have more than one function in a snippet, however. As long as the snippet is called before the eForm snippet, the functions will be in the PHP memory and available for eForm to use. eForm doesn't look for snippets, it looks for functions.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 38060
        • 29 Posts
        Do you mean, that when I call with #Function in the fields, I can not hook anything to eFormOnValidate? Interesting.

        I just saw, that my code with the snippet calls did not show correctly. So I try posting it again - this time with code view smiley

        [!DownloadFormLog!]
        [!DownloadFormValidation!]
        [!DownloadAddressValidation!]
        [!eForm? &noemail=`true` &formid=`downloadForm` &tpl=`DownloadFormHTML` &protectSubmit=`0` &gotoid=`[[DownloadId]]` &requiredClass=`requiredValue` &invalidClass=`invalidValue` &debug=`3` &eFormOnBeforeMailSent=`logDownload` eFormOnValidate=`validateZipAddress` !]


          • 28042 ☆ A M B ☆
          • 24,524 Posts
          No, I was referring to
          &eFormOnBeforeMailSent=`logDownload`validateZipAddress` 


          I suspected that was not being displayed correctly.

          Your functions MUST return true, or eForm just stops processing. You don't need to return $vmsg or any of the other arrays, eForm will deal with the modified arrays internally. You probably already know this, but that's what the &$fieldname means; you're modifying the actual original variable (arrays in this case), not just making copies and modifying the copy.

          http://php.net/manual/en/language.references.pass.php [ed. note: sottwell last edited this post 14 years, 10 months ago.]
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 38060
            • 29 Posts
            I think I was able to fix the issue back then and forgot to get back to thank you. So here is my belated Thank You.