We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36551
    • 416 Posts
    Is there something special about using Formit in a second context?

    I've got one additional context setup, which is working perfectly. Now I've added a form, one that is working in the web context. Submitting the form simply clears the all the fields on the page. There no error messages on required fields, no redirect, no errors, no message sent.

    What am I missing?

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

      • 4172
      • 5,888 Posts
      nothing special about using Formit in different contexts.

      sounds, like Formit isn't running at all.

      what is your Formit-call and your Form?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36551
        • 416 Posts
        I put this stripped down form into a chunk and placed it on a page in the primary context and it works just fine. When I put that same chunk on a page in the second context it doesn't work.

        [[!FormIt? 
        &hooks=`spam,email,redirect,FormItAutoResponder` 
        &emailTpl=`emailsendto` 
        &fiarTpl=`emailcc` 
        &fiarToField=`email`
        &emailTo=`terrybarthdesign@gmail` 
        &redirectTo=`16` 
        &validate=`firstname:required, lastname:required, email:email:required, text:required:stripTags` 
        &submitVar=`contactformsubmit`
        ]]
        
        <div id="form_container">
          <p>[[!+fi.error_message:notempty=`[[!+fi.error_message]]`]]</p>
        
          <form class="form" action="[[~[[*id]]]]" method="post">
          
          <label for="firstname"> First Name: <span class="error">[[!+fi.error.firstname]]</span> </label> 
          <input id="firstname" type="text" name="firstname" value="[[!+fi.firstname]]" /> <br /> 
        
          <label for="lastname"> Last Name: <span class="error">[[!+fi.error.lastname]]</span> </label> 
          <input id="lastname" type="text" name="lastname" value="[[!+fi.lastname]]" /> <br /> 
        
          <label for="email"> Email: <span class="error">[[!+fi.error.email]]</span> </label> 
          <input id="email" type="text" name="email" value="[[!+fi.email]]" /> <br /> 
        
          <label for="phone"> Phone: <span class="error">[[!+fi.error.phone]]</span> </label> 
          <input id="phone" type="text" name="phone" value="[[!+fi.phone]]" /> <br /> 
        
          <label for="subject"> Subject: <span class="error">[[!+fi.error.subject]]</span> </label> 
          <input id="subject" type="text" name="subject" value="[[!+fi.subject]]" /> <br /> 
        
          <label for="text"> Message: <span class="error">[[!+fi.error.text]]</span> </label> 
          <textarea id="text" name="text" rows="7" cols="77">[[!+fi.text]]</textarea>  
        
          <div class="form-buttons">
            <input name="contactformsubmit" type="submit" value="Submit" />
          </div>
        </form>
        
        </div><!--form_container-->
          • 3749
          • 24,544 Posts
          Is the second page protected in any way?

          Have you tried it directly, without launching it from the Manager?
            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
            • 36551
            • 416 Posts
            No. Not protected. Just a regular page.

            Here it is. http://www.360data.com/test.html
              • 3749
              • 24,544 Posts
              The problem may be with your base href tag. It should always be a short tag, but more important, for multiple contexts it should have an uncached tag:
              <base href="[[!++site_url]]" />


              Also, make sure you have a site_url context setting for the alternate context.

              Your page also has some significant HTML errors, Since it works in the other context, they're probably not causing the issue, but they should definitely be fixed.
                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
                • 36551
                • 416 Posts
                Bob

                I found only three html errors, which I've corrected. I updated the base ref.

                The site_url for that context is http://360data.com/

                The form still just clears. As Bruno suggested, it's as if Formit simply doesn't run.

                Is it possible for the .htaccess to affect this? I had to change the standard rewrite for no-www to www to get the second domain to resolve correctly.

                From this:
                #RewriteCond %{HTTP_HOST} !^www\.wsinc\.com [NC]
                #RewriteRule (.*) http://www.wsinc.com/$1 [R=301,L]

                to this:
                RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
                RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]

                • discuss.answer
                  • 3749
                  • 24,544 Posts
                  That's a really strange-looking rule. I've never seen the percent sign used that way, though it's technically correct and refers to the inside of the (?!www\.) term in the condition. I don't see a problem with it, although two separate condition/rule pairs like the original -- one for each context might also work.

                  Looking at the network tab in FF, I think I see the problem.

                  The base href has no www so it gets redirected by the htaccess rule. The first step is a POST request, but the redirect is a GET (not sure why), so when FormIt sees no $_POST array, it just displays the form again and the code doesn't execute.

                  Try adding a www. to the site_url.
                    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
                    • 36551
                    • 416 Posts
                    Bob

                    Brilliant!! I Needless to say I would NEVER have resolved this on my own and I almost didn't mention the change to the .htaccess.

                    Thank you!!

                    As to the rewrite rule, I really don't understand them, I just googled until I found one that worked.

                    The only thing I have to resolve now is the redirect to the thank you page. I've specified the resource ID in this context but it goes to the primary context thank you page. I think I saw something in the forums about this. I'll have to have another look.

                    Thanks again!
                      • 3749
                      • 24,544 Posts
                      Are you calling FormIt uncached in both cases?

                      [[!FormIt ...]]


                      If the ID is correct in the FormIt tag's &redirectTo property and FormIt is uncached, I don't see how it could go to the other "Thank You" page.

                      BTW, is the autoresponder working? I wouldn't think it would execute after the redirect hook (which is usually the last hook).
                        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