We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    I set up a site on a subdomain...a full implementation of MODx Revolution 2.2.6-pl with Formit set up on the contact us page. I'm also using FormSave. This is a set up I've done successfully many, many times. I also set it up to send a confirmation email to the site visitor, based on a tutorial found here:

    http://cipalabs.com/modx/articles/send-a-confirmation-email-with-formit

    The problem is that the site visitor is not receiving a confirmation (thank you) email. The hook chain seems to fail on the confirmation hook (a snippet called emailUser-contact) and the page just reloads without redirecting the visitor to the thank you page (the failing confirmation hook stops it from going beyond that point). When I take the emailUser-contact hook out of the list, the submitted form then redirects you to the thank you page properly. The rest of the system works as it should. The problem is just with the confirmation portion.

    The only thing I can think of that is different at this point is the fact that this site is running on a subdomain. Can anyone confirm or de-bunk my theory? It could be a too-obvious typo, of course, which I'm failing to see. Thanks in advance.

    This is what I have:

    The form code looks like this:

    [[!FormIt?  
    &hooks=`spam,FormSave,email,emailUser-contact,redirect`
    &submitVar=`contact_page`
    &emailSubject=`Submission from The Contact Us Page on the Company, Inc. Website`
    &emailTpl=`EmailChunk_contact_page`
    &emailTo=`[email protected]`
    &redirectTo=`28`
    &fsFormTopic=`Contact Page`
    &fsFormFields=`firstName-contact,lastName-contact,street_address-contact,city_town-contact,state-contact,zipcode-contact,telephone-contact,email-contact,text-contact` 
    &validate=`firstName-contact:required,
    lastName-contact:required,
    street_address-contact:required,
    city_town-contact:required,
    state-contact:required,
    zipcode-contact:required,
    telephone-contact:required,
    email-contact:required`
    ]]
    
    [[!+fi.error.error_message:notempty=`
    <p>[[!+fi.error.error_message]]</p>
    `]]
    
    
    <form class="form" action="[[~[[*id]]]]" method="post">
    
    <div id="contact_page_form_container">
    <h2>Your Information</h2>
    
    <div id="contact_page_form_name">
    <input name="nospam:blank" type="hidden" />
    <div id="contact_page_form_first_name">
    <label for="firstName-contact">
    * First Name:
    <span class="error">[[+fi.error.firstName-contact]]</span></label>
    <input id="firstName-contact" name="firstName-contact" type="text" value="[[+fi.firstName-contact]]" />
    </div><!-- /contact_page_form_first_name -->
    
    <div id="contact_page_form_last_name">
    <input name="nospam:blank" type="hidden" />
    <label for="lastName-contact">
    * Last Name:
    <span class="error">[[+fi.error.lastName-contact]]</span></label>
        <input id="lastName-contact" name="lastName-contact" type="text" value="[[+fi.lastName-contact]]" />
    </div><!-- /contact_page_form_last_name -->
    <div style="clear: both;"></div>
    </div><!-- /contact_page_form_name -->
    
    <div id="contact_page_form_address">
    
    <div id="contact_page_form_street_address">
    <label for="street_address-contact">* Street Address:<span class="error">[[+fi.error.street_address-contact]]</span></label><br />
    <input name="street_address-contact" type="text" id="street_address-contact" value="[[+fi.street_address-contact]]">
    </div><!-- /contact_page_form_street_address -->
    
    <div id="contact_page_form_city_town">
    <label for="city_town-contact">* City/Town:<span class="error">[[+fi.error.city_town-contact]]</span></label><br />
    <input name="city_town-contact" type="text" id="city_town-contact" value="[[+fi.city_town-contact]]">
    </div><!-- /contact_page_form_city_town -->
    
    <div id="contact_page_form_state">
    <label for="state-contact">* State:<span class="error">[[+fi.error.state-contact]]</span></label><br />
    <div id="state_select_div">
    <select name="state-contact" class="select_width">
    [[!FormItStateOptions? &selected=`[[!+fi.state-contact]]`]]
    </select>
    </div><!-- /state_select_div -->
    </div><!-- /contact_page_form_state -->
    
    <div id="contact_page_form_zipcode">
    <label for="zipcode-contact">* Zipcode:<span class="error">[[+fi.error.zipcode-contact]]</span></label><br />
    <input name="zipcode-contact" type="text" id="zipcode-contact" value="[[+fi.zipcode-contact]]">
    </div><!-- /contact_page_form_zipcode -->
    
    <div id="contact_page_form_phone_number">
    <input name="nospam:blank" type="hidden" />
    <label for="telephone-contact">
    * Telephone:<span class="error">[[+fi.error.telephone-contact]]</label>
    <input id="telephone-contact" name="telephone-contact" type="text" value="[[+fi.telephone-contact]]" />
    </div><!-- /contact_page_form_phone_number -->
    
    <div id="contact_page_form_email">
    <label for="email-contact">* Email Address:<span class="error">[[+fi.error.email-contact]]</span></label><br />
    <input name="email-contact" type="text" id="email-contact" value="[[+fi.email-contact]]">
    </div><!-- /contact_page_form_email -->
    
    </div><!-- /contact_page_form_address -->
    <div style="clear: both;"></div>
    
    <div id="contact_page_form_comments">
    <label for="text-contact">Comments:</label><br />
    <textarea name="text-contact" Id="text-contact">[[+fi.text-contact]]</textarea><br>
    </div><!-- /contact_page_form_comments -->
    
    <div id="contact_page_form_recaptcha">
    this is where the reCaptha code will go.
    </div><!-- /contact_page_form_recaptcha -->
    
    <div id="contact_page_form_comments_submit_button">
    <input type="hidden" name="subject" id="subject" value="Submission from The Contact Us Page on the Company, Inc. Website" />
    <input name="contact_page" class="contact_page_form_submit" title="contact_page" type="submit" value=" ">
    </div><!-- /contact_page_form_comments_submit_button -->
    
    </div><!-- /contact_page_form_container -->
    </form>
    


    Within the hook chain, the system calls for a snippet called emailUser-contact which contains the following:

    <?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 = 'Thank You for contacting us through the Company, Inc. website';
    $mailReplyTo = $mailFrom;
    
    //get fields values so they can be replaced in the email chunk
    $confirmationFields['firstName-contact'] = $scriptProperties['fields']['firstName-contact'];
    $confirmationFields['lastName-contact'] = $scriptProperties['fields']['lastName-contact'];
    
    //get user's email
    $mailTo= $scriptProperties['fields']['email-contact'];
      
    $text = $modx->getChunk('ConfirmationTpl-contact-page', $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);
    return false;
    }
    
    $modx->mail->reset();
    
    return true;
    


    The confirmation tpl, which is called ConfirmationTpl-contact-page (called from within the above snippet) contains this:

    <p>Hello,[[+firstName-contact]] [[+lastName-contact]]:</p>
    
    <p>Thank you for contacting us through the Company, Inc. website!  We will be getting back to you shortly.</p>


    Finally, the tpl that formats the email that the site owner gets (and called from within the Formit call), called EmailChunk_contact_page, contains this:

    <br />[[+firstName-contact]] [[+lastName-contact]] ([[+email-contact]]) wrote:<br /><br />
    
    Message: [[+text-contact]]
    
    <br /><br />
    
    First Name: [[+firstName-contact]]<br />
    Last Name: [[+lastName-contact]]<br /><br />
    Street Address: [[+street_address-contact]]<br />
    City/Town: [[+city_town-contact]]<br />
    State: [[+state-contact]]<br />
    Zipcode: [[+zipcode-contact]]<br />
    Phone Number: [[+telephone-contact]]<br />
    Email Address: [[+email-contact]]
    
    [ed. note: waizen last edited this post 13 years, 5 months ago.]
      • 3749
      • 24,544 Posts
      Is there anything in the MODX error log?

      You might try installing QuickEmail to diagnose the mail system.

      Also, some hosts are picky about the domain of the MAIL_FROM address when sending mail.
        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
        • 38290
        • 712 Posts
        Is the sub domain setup as a context and if so have domain related context settings been set like http_host and site_url
          jpdevries
          • 31902
          • 342 Posts
          Quote from: BobRay at Apr 29, 2013, 04:49 PM
          Is there anything in the MODX error log?

          Yes, the error is "An error occurred while trying to send the email:", which is the error that is written in the last part of the above emailUser-contact confirmation snippet. However, notice within the snippet, right after the error, there is this bit of code:

          '.$err


          ...which I assume is supposed to tell the system what the error is, but it doesn't. In the error log, the line just ends with "...the email:"

          Quote from: BobRay at Apr 29, 2013, 04:49 PM
          You might try installing QuickEmail to diagnose the mail system.

          Also, some hosts are picky about the domain of the MAIL_FROM address when sending mail.

          I just installed QuickEmail and it did send an email successfully. I had a feeling it might. You see, the form does send an email to the site owner (me in this case) telling me that I just had a visitor fill out the form. And, the form does populate the FormSave component of the form data properly. It's just that the confirmation snippet is failing. It's always worked before, although not now. After spending the better part of yesterday troubleshooting, I still don't have answers and the only thing I can think of that is different is that it's somehow because this install is on a subdomain. Can that be possible? Am I nuts? Yes, it could be a simple too-obvious-for-me-to-see-right-in-front-of-my-nose typo somewhere. It's driving me nuts.
            • 31902
            • 342 Posts
            Quote from: dinocorn at Apr 29, 2013, 05:46 PM
            Is the sub domain setup as a context and if so have domain related context settings been set like http_host and site_url

            The subdomain was set up from within the server control panel (DirectAdmin). The site was installed from within that subdomain. I'm not familiar with setting it up as a context...sorry for my ignorance.

            Can you expand on the "like http_host and site_url" parts?

            Thank you.
              • 3109 ☆ A M B ☆
              • 894 Posts
              When you say the site was setup as a subdomain is the main site running on the same MODX instance as the subdomain site?

              You can host multiple sites in a single MODX install these are called Contexts these can be subdomain or different sites, you can use the Context Router extra to do all the routing for the Contexts.

              From the sound of it, it seems you have the subdomain as a separate install, can you confirm that is the case.
                Benjamin Marte
                Interactive Media Developer
                Follow Me on Twitter | Visit my site | Learn MODX
                • 31902
                • 342 Posts
                Quote from: benmarte at Apr 30, 2013, 08:49 AM
                When you say the site was setup as a subdomain is the main site running on the same MODX instance as the subdomain site?

                You can host multiple sites in a single MODX install these are called Contexts these can be subdomain or different sites, you can use the Context Router extra to do all the routing for the Contexts.

                From the sound of it, it seems you have the subdomain as a separate install, can you confirm that is the case.

                Yes... it is a complete and separate install within that subdomain (multiple ones, in fact, and they all seem to be giving me the same issue, now that I'm seeing). It's all part of my evil plan to set up pre-configured basic starter sites on separate subdomains, then when I have a new project, use a site within a given subdomain to act as a head start, with TVs, chunks, backend configurations, etc., already set to go. I've moaned and groaned about some of my issues here:

                https://forums.modx.com/thread/83740/multiple-installs-of-modx-revo-on-one-account-but-on-different-subdomains#dis-post-462147

                and here:

                https://forums.modx.com/thread/83420/how-to-use-a-starter-site-and-use-that-to-get-a-head-start-on-new-modx-sites#dis-post-460191

                ...in the past. For the most part, I think I got most of those issues sorted out but I'm now experiencing the one on this thread. I'm starting to wonder if I should even worry about this as an issue since the confirmation script seems to work when on a root level. But, I'd like to confirm if this issue has to do with the fact that it is on a subdomain or something else before I lose the rest of my hair color.

                Thanks for responding.
                  • 3109 ☆ A M B ☆
                  • 894 Posts
                  I would start by removing some of the hooks in order to see which one may be causing the issue I would start by removing the custom hook you made and FormSave and seeing if the form submits fine then add the custom hook and last add FormSave.

                  I have never used either of these hooks so I think one of them is the culprit.

                  Good Luck.
                    Benjamin Marte
                    Interactive Media Developer
                    Follow Me on Twitter | Visit my site | Learn MODX
                    • 31902
                    • 342 Posts
                    Quote from: benmarte at Apr 30, 2013, 09:46 AM
                    I would start by removing some of the hooks in order to see which one may be causing the issue I would start by removing the custom hook you made and FormSave and seeing if the form submits fine then add the custom hook and last add FormSave.

                    I have never used either of these hooks so I think one of them is the culprit.

                    Good Luck.

                    Yes, I had done that. That's how I got to thinking that it was that hook that is causing the trouble. I also reworded the error message I spoke of in Reply#4 above, just to make sure that's where the error message that I saw in the error log was coming from.

                    What happened is that the form just reloads on the contact page, without proceeding to the next hook in the line (redirect). As soon as I had taken that hook out and tested, the form redirected just fine. It fails at the custom hook and stops. There is something about that hook but I don't see what at the moment. [ed. note: waizen last edited this post 13 years, 5 months ago.]