We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Willi Waizenegger Reply #1, 14 years ago
    I have a small contact form that I want to add to every page of a site, down in the footer.

    The form does not want to work at all from the footer...it just reloads site on the home page, acting on the:

    <form class="form" action="[[~[[*id]]]]" method="post">


    ...part of the code, I guess. Doesn't even redirect to my chosen redirect page.

    However, when I take the exact same code and add it to an individual resource (through a chunk) and use the form directly through that resource, the thing works great.

    So, the form running through the footer that is being called on any page you visit does not work, yet the test version of it (identical code) that is called through only one page works great.


    Both versions of the code look like this:

    The call:

    [[!FormIt?  
    &hooks=`spam,FormSave,email,emailUser-footer,redirect`
    &emailSubject=`Submission from The XXXX website`
    &emailTpl=`EmailChunk_footer`
    &emailTo=`[email protected]`
    &redirectTo=`3`
    &fsFormTopic=`Contact`
    &fsFormFields=`name,email,text`  
    &validate=`nospam:blank,
    name:required,
    email:required,`
    ]]
    
    [[!+fi.error.error_message:notempty=`
    <p>[[!+fi.error.error_message]]</p>
    `]]
    
    
    <div id="contact_form">
    <form class="form" action="[[~[[*id]]]]" method="post">
        <div id="footer_questions_box">
        <h1><strong>QUESTIONS?</strong> GET IN TOUCH.</h1>
        <p>We specialize in customer satisfaction. Feel free to get in touch with us using this form.</p>
        
        <div id="name_field"><input name="nospam:blank" type="hidden" />
        <label for="name">Name Here:<span class="error">[[+fi.error.name]]</span></label>
    <input id="name" name="name" type="text" value="[[+fi.name]]"  />
        </div><!--name_domain_fields -->
        
        <div id="email_field"><input name="nospam:blank" type="hidden" />
        <label for="email">Email Here:<span class="error">[[+fi.error.email]]</span></label>
    <input id="email" name="email" type="text" value="[[+fi.email]]" />
        </div><!--email_field -->
        
        <div id="message_field"><input name="nospam:blank" type="hidden" />
        <label for="text">Your Message Here:</label>
    <textarea id="text" cols="50" rows="7" name="text">[[+fi.text]]</textarea>
        </div><!--message_field -->
    <input type="hidden" name="subject" id="subject" value="Submission from The XXXX website" />
    
    <div id="footer_submit_button_container">
        <input type="submit" value="Submit" class="footer_submit_button" />
    </div>
      
        
        </div><!-- footer_questions_box -->
        </form>
    


    ConfirmationTpl-footer:

    Hello,[[+name]]:
    
    <p>Thank you for your interest in XXXX! We will be getting back to you shortly.</p>
    


    EmailChunk_footer:

    <br />[[+name]] ([[+email]]) wrote:<br /><br />
    
    Message: [[+text]]
    


    emailUser-footer (snippet):

    <?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 XXXX';
    $mailReplyTo = $mailFrom;
    
    //get fields values so they can be replaced in the email chunk
    $confirmationFields['text'] = $scriptProperties['fields']['text'];
    $confirmationFields['name'] = $scriptProperties['fields']['name'];
    $confirmationFields['email'] = $scriptProperties['fields']['email'];
    
    //get user's email
    $mailTo= $scriptProperties['fields']['email'];
      
    $text = $modx->getChunk('ConfirmationTpl-footer', $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;
    
    


    How do I get this to work? What am I missing?

    Thank you in advance.

    Running the following:
    FormIt 2.1.1
    Revo 2.2.2-pl
    FormSave 1.0.1
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      For one thing you have an extra comma at the end of the last property
      &validate=`nospam:blank,
      name:required,
      email:required,`

      I've had FormIt fail altogether because of that.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 31902
        • 342 Posts
        Willi Waizenegger Reply #3, 14 years ago
        Wow, Susan, that was it. It worked as soon as I took that comma off.

        Interesting that it worked installed from a one-page installation, but not through the footer. Same code (copy/paste) on both. Whatever...at least it works.

        Thanks again! [ed. note: waizen last edited this post 14 years ago.]
          • 31902
          • 342 Posts
          Sorry to resurrect this thread but the same thing has started happening again. This time, I made sure there was no trailing comma, as the above solution suggested.

          The same symptoms again but this time, I cannot make it happen from the footer by adding the form code (living inside a chunk) directly in the footer code.

          I don't think it matters, but the form code lives inside a chunk called "footer_form_code". That chunk gets called up within the footer code, which is itself a chunk, called "footer". The footer chunk then gets called up in the template.

          Also, I don't think it matters but figure I'll mention it: this site is running with user friendly URLs on, although the domain is not propagated to it yet. Working on it through IP address. As in, http://xxx.xxx.xxx.xx/~client/index.php.

          This time, the "footer_form_code" chunk displays the same problem, even if I place the chunk directly within the template. For testing purposes, I took another form code chunk, from another project that I know works, and placed it in the footer to see if that runs. Nope.

          I tried taking the form code directly out of the chunk and place it, as is, on the template directly. Same problem. The page doesn't submit and just refreshes.

          Interestingly, I take the "footer_form_code" chunk and place it on the page through a template variable (on that page I happen to have a TV under the content to optionally place code there if I want to...it's a standard practice with me on most sites).

          In that case, it works. Something about running it through a TV is making it work.


          What is going on here? Below is all the code that is coming into play.

          Chunk called footer_form_code:
          [[!FormIt?  
          &hooks=`spam,hook.RampartFormIt,FormSave,email,emailUser-footer,redirect`
          &emailSubject=`Submission from XXXXXXX Website Footer Mailing List Form`
          &emailTpl=`EmailChunk-footer`
          &emailTo=`[email protected]`
          &redirectTo=`12`
          &fsFormTopic=`Footer-Contact`
          &fsFormFields=`firstName,lastName,company,email` 
          &validate=`firstName:required,lastName:required,email:required`
          ]]
          
          [[!+fi.error.error_message:notempty=`
          <p>[[!+fi.error.error_message]]</p>
          `]][[!+fi.error.rampart]]
          
          <form class="form" action="[[~[[*id]]]]" method="post">
          
          <div id="footer_form_first_name"><input name="nospam:blank" type="hidden" />
          <label for="firstName">First Name:<span class="error">[[+fi.error.firstName]]</span></label>
          <input name="firstName" type="text" class="footer_form_first_name"  value="[[+fi.firstName]]" />
          </div><!-- /footer_form_first_name -->
          
          <div id="footer_form_last_name"><input name="nospam:blank" type="hidden" />
          <label for="lastName">Last Name:<span class="error">[[+fi.error.lastName]]</span></label>
          <input name="lastName" type="text" class="footer_form_last_name" value="[[+fi.lastName]]" />
          </div><!-- /footer_form_last_name -->
          
          <div id="footer_form_company_name"><input name="nospam:blank" type="hidden" />
          <label for="company">Company Name:</label>
          <input name="company" type="text" class="footer_form_company" value="[[+fi.company]]" />
          </div><!-- /footer_form_company_name -->
          
          <div id="footer_form_email"><input name="nospam:blank" type="hidden" />
          <label for="email">Email Address:<span class="error">[[+fi.error.email]]</span></label>
          <input name="email" type="text" class="footer_form_email" value="[[+fi.email]]">
          </div><!-- /footer_form_email -->
          
          <input type="hidden" name="subject" id="subject" value="Submission from XXXXXXX Website Footer Mailing List Form" />
          <input name="Submit_Button" class="footer_form_submit_button" title="Submit_Button" type="submit" value="">
          </form>


          emailTpl chunk called EmailChunk-footer:
          <br />[[+firstName]] [[+lastName]] ([[+email]]) wrote:<br /><br />
          
          First Name: [[+firstName]]<br />
          Last Name: [[+lastName]]<br />
          Email Address: [[+email]]<br />
          Company Name: [[+company]]


          confirmationTpl chunk called ConfirmationTpl-footer:
          Hello,[[+firstName]] [[+lastName]]:
          
          <p>Thank you for your interest in XXXXXX!  Please provide a few days for a response to any questions or concerns you may have.</p>


          Confirmation snippet called emailUser-footer:
          <?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 XXXXX';
          $mailReplyTo = $mailFrom;
          
          //get fields values so they can be replaced in the email chunk
          $confirmationFields['firstName'] = $scriptProperties['fields']['firstName'];
          $confirmationFields['lastName'] = $scriptProperties['fields']['lastName'];
          $confirmationFields['company'] = $scriptProperties['fields']['company'];
          
          //get user's email
          $mailTo= $scriptProperties['fields']['email'];
            
          $text = $modx->getChunk('ConfirmationTpl-footer', $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;


          Formit 2.1.2
          MODx Revo 2.2.5-pl [ed. note: waizen last edited this post 13 years, 9 months ago.]
            • 10208 ☆ A M B ☆
            • 1,780 Posts
            How are you calling the footer TV in the template? Anything special about that? And how is the footer chunk called in the template? Same... what's different about it?

            Try uncaching the chunk in the template, or maybe the form chunk too. I have a modal window TV that won't take a plain chunk (specifically, a contact form chunk), snippet, or TV but WILL work by calling them uncached.
              Frogabog- MODX Websites in Portland Oregon
              "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
              Having server issues? These guys have MODX Hosting perfected - SkyToaster