We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35756
    • 166 Posts
    Hello there!

    I'm trying to get the hook "email:email:required" to be working properly, but it doesn't.

    The form i'm using comes straight from the RTFM like this:

    <p>[[!FormIt? &hooks=`spam,email,redirect` &emailTpl=`Mail-Anmeldung` &emailTo=`[email protected]` &redirectTo=`3` &validate=`email:email:required` ]]</p>
    
    <h2>Contact Form</h2>
    <p>[[!+fi.error_message:notempty=`</p>
    <p>[[!+fi.error_message]]</p>
    <p>`]]</p>
    <form class="form" action="[[~[[*id]]]]" method="post">
    <input type="hidden" name="nospam:blank" value="" /> 
    
    <label for="email"> Email: <span class="error">[[!+fi.error.email]]</span> </label> 
    <input id="email" type="text" name="email" value="[[!+fi.email]]" /> 
    
    <br class="clear" /> [[!+formit.recaptcha_html]] [[!+fi.error.recaptcha]] <br class="clear" />
    <div class="form-buttons"><input type="submit" value="Send Contact Inquiry" /></div>
    </form>


    When I try to submit the form without any entries the hook "email:required" works well, the form does not get submitted as expected.

    But when I try to type in anything else than a "real email-adress" the form gets "validated" and submitted, the confirmation mail is sent.

    I re-installed FormIt with the latest release right now and tried again to submit the form with a single "1" enterred in the input field, the form gets "validated" and "submitted" again...

    What do I miss?
      • 44580
      • 189 Posts
      try: type="email" in your <input>.
        • 35756
        • 166 Posts
        Quote from: gissirob at Jul 08, 2014, 10:05 PM
        try: type="email" in your <input>.

        Hello gissirob!

        And thank you for your reply...

        This works, didn't know this way...but it doesn't rely on the hook and it behaves different than "normal". So I'd still like to get rid of the issue and use it the normal way...it has to work somehow, but I don't see the error...
          • 44580
          • 189 Posts
          Hmmm. I'm not using Formit at the moment, but I believe the following once worked:
          <label for="email">Email</label>
          <span class="error">[[!+fi.error.email]]</span>
          <input type="text" name="email" id="email" value="[[!+fi.email]]" />

          The only difference to your code is the <span> is outside the <label>. You could try that.
            • 35756
            • 166 Posts
            Thx again gissirob, but this didn't work as well sad

            I don't get it at all!? I'm using this form on another site and there it's working fine, with correct email-validation. I excluded all used scripts on the site to test if any script might be harming it, but no changes.

            Finally i want to create a customHook as well, which works.

            There must be a solution to implement a validation based on PHP to the following code of the snippet:

            if ($value == 'Your email-adress') {
            $validator->addError($key,'Please type an email!');
            }
            
            else {
            return $success;
            }


            But so far i had no luck in doing this...
              • 35756
              • 166 Posts
              now by using this customHook the email gets verified:

              $email = $value;
              if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
                   //Valid email!
              return $success;
              }
              else {
                  $validator->addError($key,'Bitte gebe eine gültige Email-Adresse ein!');
              }


              But - no redirect anymore sad

              [[!FormIt?
              &customValidators=`Form-Check-Email`
              &store=`1`
              &hooks=`spam,email,redirect`
              &emailTo=`[email protected]`
              &emailTpl=`MyEmailTpl`
              &redirectTo=`3`
              &validate=`
              name:required,
              email:Form-Check-Email:required,
              text:required`
              ]]
                • 35756
                • 166 Posts
                the no-redirect issue was related to a customhook i added to the FormIt-call...

                <?php
                //configuration
                $mailFrom = $modx->getOption('emailsender'); //OR USE YOUR OWN;
                $mailFromName = $modx->getOption('site_name'); //OR USE YOUR OWN;
                $mailSender = $modx->getOption('site_name'); //OR USE YOUR OWN;
                $mailSubject = 'SUBJECT';
                $mailReplyTo = $mailFrom;
                 
                //get fields values so they can be replaced in the email chunk
                $confirmationFields['name'] = $scriptProperties['fields']['name'];
                $confirmationFields['betreff'] = $scriptProperties['fields']['betreff'];
                $confirmationFields['email'] = $scriptProperties['fields']['email'];
                 
                //get user's email
                $mailTo= $scriptProperties['fields']['email'];
                   
                $text = $modx->getChunk('ConfirmationTpl-Anmeldung', $confirmationFields);
                   
                $modx->getService('mail', 'mail.modPHPMailer');
                $modx->mail->set(modMail::MAIL_BODY,$text);
                $modx->mail->set(modMail::MAIL_FROM,$mailFrom);
                $modx->mail->set(modMail::MAIL_FROM_NAME,$mailFromName);
                $modx->mail->set(modMail::MAIL_SENDER,$mailSender);
                $modx->mail->set(modMail::MAIL_SUBJECT,$mailSubject);
                $modx->mail->address('to',$mailTo);
                $modx->mail->address('reply-to',$mailReplyTo);
                $modx->mail->setHTML(true);
                 
                if (!$modx->mail->send()) {
                    $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
                $modx->mail->reset();
                return true;
                }
                 
                $modx->mail->reset();
                 
                return true;


                I changed line 29-32 to get a return true, because the error is inbetween this original code-part:

                if (!$modx->mail->send()) {
                   $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
                return false;
                }


                I don't understand what is the error there, because the mail gets send as wanted. So I did this dirty workaround to get my page-redirect. But I'D like to know why there is an error and how I can solve it.