We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44437
    • 74 Posts
    I am trying to validate a phone field in Formit by using custom hooks. The phone format must be ###-###-####. However, when I using getValues() in my snippet, I receive 500 server error. The error from the error logs reads:

    PHP Fatal error: Call to a member function getValues() on a non-object in /home/user/www/core/cache/includes/elements/modsnippet/34.include.cache.php on line 9, referer: http://www.mywebsite.com/en/contact-form

    Here is my code:

    [[!FormIt?
    &hooks=`recaptcha,spam,FormSave,email,redirect`
    &customValidators=`FacebookCountryRedirect`
    &emailTpl=`FbContactEmailTpl`
    &emailSubject=`Facebook Contact Form`
    &emailTo=`[email protected]`
    &fsFormTopic=`Facebook Contact`
    &validate=`country:required,
    fname:required,
    lname:required,
    mobile:FacebookCountryRedirect,
    email:email:required,
    vehicle-make-model:required,
    age:required,
    agreement:required`
    &redirectTo=`2`
    &redirectParams=`{"country":"[[!+fi.country]]"}`
    ]]

    SNIPPET
    <?php
    $hook = $scriptProperties['hook'];

    $country='';

    if( is_object($hook) ){

    $countries = $hook->getValue('fname');

    if ($countries == 'Jevon')
    {
    $country='Anguilla';
    }

    }
    else{ $countries='batman';}

    return $countries;

    Can anyone please help me with this issue?



    This question has been answered by BobRay. See the first response.

    [ed. note: random_noob last edited this post 12 years, 3 months ago.]
      • 44437
      • 74 Posts
      Did I post this question in the wrong section?
      • discuss.answer
        • 3749
        • 24,544 Posts
        That snippet code looks like your validator.

        Validators don't get the $hook variable. Instead, the posted value is set in the $value variable, so all you should need is this:

        $countries = $value;


        Also, AFAIK, validators can only return true (succcessful validation) or false (failed validation).

        Your validator can set placeholders with $modx->setPlaceholder('key', 'value'), but the placeholder tags will have to exist in the form.

        http://rtfm.modx.com/display/ADDON/FormIt.Validators [ed. note: BobRay last edited this post 13 years, 2 months ago.]
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 44437
          • 74 Posts
          Ohhhhh ok. I understand what you are saying and I got the form to work. Thanks a million.

          Cheers.