We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Was pleased that Formit 3.0.3 made the snippet compatible with PHP 7.1, most particularly:

    Replace ereg() functions with preg_match() for PHP compatibility (#98)

    So we no longer get the ereg error (which was usually on email validation) when the server is set to PHP 7.1.

    However, despite entering a valid email address into the field validation continues to insist that we haven't input a valid email address even though it is valid so we had to remove email validation entirely to allow the form to be submitted.

    I created a much simplified form that basically just asks for an email but still, if input [email protected] (or indeed any email, not just with the gmail.com domain) validation insists it's not a valid email.

    Here is my call:

    [[!FormIt?
        &hooks=`spam,email,FormItAutoResponder,FormItSaveForm,redirect`
        &submitVar=`go`
        &emailTpl=`request`
        &emailTo=`[[#[[++admin_page_id]].tv.emailrecipients]]` 
        &emailSubject=`[[#[[++admin_page_id]].tv.emailsubject]]`
        &redirectTo=`[[++thankyou_page_id]]`
        &store=`1`
        &fiarTpl=`response`
        &fiarSubject=`[[#[[++admin_page_id]].tv.emailsubjectRecipient]]`
        &fiarToField=`email`
        &fiarFrom=`[[#[[++admin_page_id]].tv.emailfrom]]`
        &fiarReplyTo=`[[#[[++admin_page_id]].tv.emailreplyto]]`
        &fiarFromName=`[[#[[++admin_page_id]].tv.emailreplyname]]`
        &validate=`email:email:required`
        &vTextRequired=`[[$ERRORrequiredGenericTPL]]`
        &formName=`TESTPilot`
        &formFields=`email`
        &fieldNames=`email==Email`
    ]]
    
    
    <div class="row">
        
        <div class="col-xs-12">
    
            <form role="form" action="[[~[[*id]]]]" method="post">
                <input type="hidden" name="nospam:blank" value="" />
                    <div class="form-group">
                        [[!+fi.error.email]]
                        <label for="email">[[%custom.contact_email? &topic=`custom` &language=`[[++cultureKey]]`]]</label>
                        <input type="email" class="form-control" name="email" id="email" value="[[!+fi.email]]" />
                    </div> 
                    <input type="submit" class="btn btn-custom pull-right" name="go" value="[[%custom.contact_submit? &topic=`custom` &language=`[[++cultureKey]]`]]">
            </form>
    
            
        </div>
        
    </div>
    


    I'm aware that the spam hook can effect email as well but we removed that and tried again and there was no difference.

    We also tried removing: id="email"
    We tried using only name="email" or id="email"
    We tried input type="email" or input type="text"

    A valid email address is reported as invalid in all the above variations.

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

      • 3749
      • 24,544 Posts
      I tested the email validation code locally and it's failing for me too.

      This is the part that's reporting the email as invalid ($value is the email address):

      $email_array = explode("@", $value);
         $local_array = explode(".", $email_array[0]);
         for ($i = 0; $i < sizeof($local_array); $i++) {
             $pattern = "^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$";
             $condition = $this->config['use_multibyte'] ? @mb_ereg($pattern, $local_array[$i]) : @preg_match('/' . $pattern . '/', $local_array[$i]);
             if (!$condition) {
                 return $this->_getErrorMessage($key, 'vTextEmailInvalid', 'formit.email_invalid', array(
                     'field' => $key,
                     'value' => $value,
                 ));
             }
         }


      The pattern is so tortuous that it's difficult to see where it's going wrong.

      If you change this:

      if (!$condition)


      to this:

      if (false)


      It should skip that test, though all it will be checking then is the domain, length and presence of the @ sign.

        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
      • discuss.answer
        • 3749
        • 24,544 Posts
        I think I have it. The two forward slashes in the pattern are not escaped with preceding backslashes (thank you Rubular Regular Expression Editor).


        So this line:

        $pattern = "^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$"
        ;

        should be:

        $pattern = "^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$";


        I've submitted a pull request with the fix. In the meantime, you can just paste the line above to replace line 432 of the core/components/formit/model/formit/fivalidator.class.php file.
        [ed. note: BobRay last edited this post 6 years, 6 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
        • Great, that did the trick, thanks.