We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21419
    • 84 Posts
    I’ve been all over the forums, reading every FormIt error I can find and I just can’t figure out what is going on. All pertinent information is below.

    I’m getting no errors in the error log.
    The form does not redirect and does not send an email.
    It’s hosted on Mosso (Rackspace Cloud Sites)
    I have tested PHP Mail successfully (though I have also tried the form with SMTP mail turned on in System Settings with no success).

    I’m usually pretty good at either solving the problem or finding the solution in the forums, but I’m coming up completely empty on this one. All help is appreciated.

    Web Page
    http://www.tsminsurance.com.php5-18.websitetestlink.com/contact/

    Using Revo 2.0.6-pl (traditional)
    FormIt 1.5.3

    Server OS: Linux
    Server Version: Apache/2.2
    PHP Version: 5.2.13
    MySQL Version: 5.0.77
    pdo_mysql: YES


    I’m using the example from the MODx Wiki.

    FormIt (&emailTo on site is real)
    [[!FormIt?
       &hooks=`recaptcha,spam,email,redirect`
       &emailTpl=`MyEmailChunk`
       &emailTo=`[email protected]`
       &redirectTo=`1`
       &validate=`name:required,
          email:email:required,
          subject:required,
          text:required:stripTags,
          numbers:required,
          colors:required`      
    ]
    


    Form HTML
    <h2>Contact Form</h2>
    
    [[!+fi.error.error_message:notempty=`<p>[[!+fi.error.error_message]]</p>`]]
    
    <form action="[[~[[*id]]]]" method="post" class="form">
        <input type="hidden" name="nospam:blank" value="" />
    
        <label for="name">
            Name:
            <span class="error">[[+fi.error.name]]</span>
        </label>
        <input type="text" name="name" id="name" value="[[+fi.name]]" />
    
        <label for="email">
            Email:
            <span class="error">[[+fi.error.email]]</span>
        </label>
        <input type="text" name="email" id="email" value="[[+fi.email]]" />
    
        <label for="subject">
            Subject:
            <span class="error">[[+fi.error.subject]]</span>
        </label>
        <input type="text" name="subject" id="subject" value="[[+fi.subject]]" />
    
        <label for="text">
            Message:
            <span class="error">[[+fi.error.text]]</span>
        </label>
        <textarea name="text" id="text" cols="55" rows="7" value="[[+fi.text]]">[[+fi.text]]</textarea>
    
    
        <label>
            Numbers:[[+fi.error.numbers]]
            <select name="numbers" value="[[+fi.numbers]]">
                <option value="">Select an option...</option>
                <option value="one" [[!+fi.numbers:FormItIsSelected=`one`]]>One</option>
                <option value="two" [[!+fi.numbers:FormItIsSelected=`two`]]>Two</option>
                <option value="three" [[!+fi.numbers:FormItIsSelected=`three`]]>Three</option>
            </select>
        </label>
    
        <label>
            Colors:[[+fi.error.colors]]
            <input type="hidden" name="colors[]" value="" />
        </label>
        <ul>
          <li>
            <label><input type="checkbox" name="colors[]" value="red" [[!+fi.colors:FormItIsChecked=`red`]] /> Red</label>
          </li>
          <li>
            <label><input type="checkbox" name="colors[]" value="blue" [[!+fi.colors:FormItIsChecked=`blue`]] /> Blue</label>
          </li>
          <li>
            <label><input type="checkbox" name="colors[]" value="green" [[!+fi.colors:FormItIsChecked=`green`]] /> Green</label>
          </li>
        </ul>
    
        <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>
    


    MyEmailChunk
    This is the Formit Email Chunk.
    
    <br />[[+name]] ([[+email]]) Wrote: <br />
    
    [[+text]]
    
      • 7914
      • 137 Posts
      Hello,
      Here is what I am using and everything is working. (Also using RS Cloud)

      This is my form:
      [[!FormIt?
         &hooks=`email,redirect,spam`
         &emailTpl=`survey_email_tpl`
         &emailTo=`[email protected]`
         &emailFromName=`From Name <[email protected]>`
         &emailSubject=`E-mail Subject`
         &redirectTo=`83`
         
         &validate=`looking_for:required:stripTags,
      			  name:required,
      			  company:required,
      			  phone:required,
      			  email:email:required, 
      			  qaws:contains=wet`
      ]]
      
      <p>[[+fi.error.error_message]]</p>
      
      <li><span class="error">[[+fi.error.looking_for]]</span>
      		<label for="looking_for">What are you looking for?</label>
      		<textarea id="looking_for" name="looking_for" cols="50" rows="3">[[+fi.looking_for]]</textarea></li>
      
      ... rest of html form follows ...
      


      My email template looks something like this...
      <p>Name: [[+name]]<br />
      Company: [[+company]]<br />
      Phone Number: [[+phone]]<br />
      E-mail: [[+email]]</p>
      
      ... and so on ...
      


      Hope this helps...
        • 22019
        • 390 Posts
        Take out the recaptcha hook, as it’s failing the first hurdle - it doesn’t look like you’ve specified an API key. Have a look here
        http://rtfm.modx.com/display/ADDON/FormIt.Hooks.recaptcha
        at how to use this hook properly. Similarly for the spam hook, which as far as I can see, does nothing the way you (and the tutorial) have it configured.

          Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
          • 22019
          • 390 Posts
          @dowhatnow - For the record your spam hook will never fire, as it’s after the redirect hook (the order of the hooks matters). Also your ’contains’ validator should be =`wet` with backticks.
            Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
            • 7914
            • 137 Posts
            @odeclas thank you for the tip!
              • 21419
              • 84 Posts
              Thanks for all the input!

              Here are the steps I’ve taken:

              1. Removed the reCaptcha hook. Still failing. (thanks for pointing that out though, odeclas)

              2. Added the &emailFromName and &emailSubject (pertinent parameters I did not have in my snippet). Fail.

              3. Used dowhatnow’s snippet (with reordered hooks and minus company: required and qaws=wet). Worked... once?!

              The email was sent and I was redirected to the Home page.

              Tried it again and it failed. Tried again and it worked. It’s working about 1 in 10 attempts.

              Is there any way to run FormIt in debug? This has been incredibly frustrating. I have no idea why it’s failing or why it works occassionally.
                • 3749
                • 24,544 Posts
                When it fails, are you getting any error messages on the screen or in the MODx log?

                It could be a timeout error or possibly your host limits the number of emails send in a given time period.

                Here’s a snippet I wrote called QuickEmail that’s designed to diagnose email problems. It might help.

                I tried to make a package out of it, but PackMan doesn’t like it for some reason. It will look a little funky without its parameters set, but just putting:

                [[!QuickEmail? &debug=`1`]]


                on a page and previewing the page might give you some clues.

                Here’s the snippet:

                <?php
                /**
                 * QuickEmail
                 * 
                 * Copyright 2010 by Bob Ray <http://bobsguides.com>
                 *
                 * QuickEmail is free software; you can redistribute it and/or modify it
                 * under the terms of the GNU General Public License as published by the Free
                 * Software Foundation; either version 2 of the License, or (at your option) any
                 * later version.
                 *
                 * QuickEmail is distributed in the hope that it will be useful, but WITHOUT ANY
                 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
                 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
                 *
                 * You should have received a copy of the GNU General Public License along with
                 * QuickEmail; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
                 * Suite 330, Boston, MA 02111-1307 USA
                 *
                 * @package quickemail
                 */
                /**
                 * QuickEmail - A simple email snippet for MODx Revolution
                 *
                 * @package quickemail
                 */
                
                /* save some typing */
                $sp = $scriptProperties;
                
                /* get the MODx mailer object */
                $modx->getService('mail', 'mail.modPHPMailer');
                
                /* set default values */
                $output = '';
                $debug = $modx->getOption('debug',$sp,false);
                $debug = stristr('no',$modx->getOption('debug',$sp,false))? false : $debug;
                $tpl = $modx->getOption('msgTpl',$scriptProperties,false);
                $message = $modx->getOption('message',$sp,false);
                $message = empty($message)? 'Default Message' : $message;
                $subject = $modx->getOption('subject',$sp);
                $subject = empty($subject)? 'Default Subject' : $subject;
                $to = $modx->getOption('to',$sp);
                $to = empty($to)? $modx->getOption('emailsender') : $to;
                $toName = $modx->getOption('toName',$sp);
                $toName = empty($toName)? $modx->getOption('emailsender') : $to;
                $fromName = $modx->getOption('from',$sp);
                $fromName = empty($fromName)? $to : $fromName;
                $emailSender = $modx->getOption('emailSender',$sp);
                $emailSender = empty($emailSender) ? $modx->getOption('emailsender',null,false): $emailSender;
                $replyTo = $modx->getOption('replyTo',$sp);
                $replyTo = $modx->getOption('emailsender');
                $html = $modx->getOption('allowHtml',$sp,false);
                $html = stristr('no',$modx->getOption('allowHtml',$sp,false))? false : $html;
                $hideOutput = $modx->getOption('hideOutput',$sp,false);
                $hideOutput = stristr('yes',$modx->getOption('hideOutput',$sp,false))? true : $hideOutput;
                $failureMessage = $modx->getOption('failureMessage',$sp,false);
                $successMessage = $modx->getOption('successMessage',$sp,false);
                $errorHeader = $modx->getOption('errorHeader',$sp,false);
                
                if (! empty ($tpl) ) {
                    $msg = $modx->getChunk($msgTpl);
                    if (empty($msg) && $debug) {
                        $output .= '<br />Error: Cannot find Tpl chunk: ' . $tpl;
                    }
                } else {
                    $msg = $message;
                }
                
                if (! $msg) {
                   $msg = 'Default Message';
                }
                
                if ($debug) {
                    $output .= '<h3>System Settings (used if property is missing):</h3>';
                    $output .= '<b>emailsender System Setting:</b> ' .$modx->getOption('emailsender',$sp);
                    $output .= '<br /><b>site_name System Setting:</b> ' .$modx->getOption('site_name',$sp);
                
                    $output .= '<h3>Properties (from parameters, property set, or snippet default properties:</h3>';
                    $output .= '<b>Tpl chunk name:</b> ' . $modx->getOption('msgTpl',$sp);
                    $output .= '<br /><b>subject:</b> ' . $modx->getOption('subject',$sp);
                    $output .= '<br /><b>to:</b> ' . $modx->getOption('to',$sp,'empty');
                    $output .= '<br /><b>fromName:</b> ' . $modx->getOption('fromName',$sp);
                    $output .= '<br /><b>replyTo:</b> ' . $modx->getOption('replyTo',$sp);
                    $output .= '<br /><b>emailSender:</b> ' . $modx->getOption('emailSender',$sp);
                    $output .= '<br /><b>allowHtml:</b> ' . $modx->getOption('allowHtml',$sp);
                    $output .= '<br /><b>message:</b> ' . $modx->getOption('message',$sp);
                
                
                    $output .= '<h3>Final Values (actually used when sending email):</h3>';
                    $output .= '<b>subject:</b> ' .$subject;
                    $output .= '<br /><b>to:</b> ' .$to;
                    $output .= '<br /><b>fromName:</b> ' .$fromName;
                    $output .= '<br /><b>replyTo:</b> ' .$replyTo;
                    $output .= '<br /><b>emailSender:</b> ' .$emailSender;
                    $output .= '<br /><b>allowHtml:</b> ' . $html;
                    $output .= '<br /><b>Message Body:</b> ' . $msg;
                    
                }
                
                $modx->mail->set(modMail::MAIL_BODY, $msg);
                $modx->mail->set(modMail::MAIL_FROM, $emailSender);
                $modx->mail->set(modMail::MAIL_FROM_NAME, $fromName);
                $modx->mail->set(modMail::MAIL_SENDER, $emailSender);
                $modx->mail->set(modMail::MAIL_SUBJECT, $subject);
                $modx->mail->address('to', $to, $toName);
                $modx->mail->address('reply-to', $replyTo);
                $modx->mail->setHTML($html);
                if ($debug) {
                    ob_start();
                    echo '<pre>';
                
                    if ($modx->getOption('mail_use_smtp') ) {
                        $modx->mail->mailer->SMTPDebug = 2;
                    }
                }
                $sent = $modx->mail->send();
                
                if ($debug) {
                    echo '</pre>';
                    $ob = ob_get_contents();
                    ob_end_clean();
                }
                
                $modx->mail->reset();
                
                if ($sent) {
                    $output .= $successMessage;
                    if ($debug) {
                       $output .= $ob;
                    }
                } else  {
                
                    $output .= $failureMessage;
                    $output .= $errorHeader;
                    $output .= $modx->mail->mailer->ErrorInfo;
                    if (!empty($ob)) {
                        $output .= $smtpErrorHeader;
                    }
                    $output .= $ob;
                    
                    
                }
                $output = $hideOutput && (! $debug )? '' : $output;
                return $output;
                  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
                  • 21419
                  • 84 Posts
                  Bob,

                  Thanks! That’s a great utility! It sends me emails every time, so the basic emailing function is definitely working.

                  I’ve tried changing my system settings and using SMTP and not using SMTP and I just can’t get the form to work. When I submit the form, the page simply refreshes, emptying the fields. It’s definitely failing on email though. If I strip out spam, it fails. Strip out spam and email, it redirects to the home page, as it should.

                  I think I’m going to have to rebuild the site in Evo. It’s certainly not something I want to do, primarily because I want to move forward with MODx and I really like a lot of what Revo does. But I have a bunch of complicated forms that need to be developed for this site and not being able to get the simplest version to work consistently is very discouraging and I need to get this project done.

                  I appreciate all of the help.
                    • 22019
                    • 390 Posts
                    If it refreshes, then it is validating, but falling over at one of the hooks. The simplest reason for this is usually one of three things:

                    • Backticks either unclosed or apostrophes used by mistake (although this tends to error more than do nothing)
                    • Chunk name does not exactly match (case sensitive) that specified in the tpl parameter
                    • The form has been copied in to a richtext field, and TinyMCE has replaced the ampersands (&) with HTML encoding - so it effectively does nothing - ie make sure richtext editor is either off permanently or toggled off

                    In this case I’d also triple check the email settings you’re giving Formit for it to send you an email (and check Junk folder).
                      Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
                      • 21419
                      • 84 Posts
                      Odeclas,

                      I appreciate it. I have actually done all of those things. All backticks are in place. Chunk is correct and I am not using Rich Text in the Manager for that page. I’ve also copied, converted to ASCII and repasted just to be sure there wasn’t some errant character in there.

                      The most frustrating aspect has been when it would work once and not again. I’m in the middle of rebuilding in Evo right now. At some point, I’ll come back to Revo, but I’ve lost way too much time between this and other educational issues along the way.