We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36551
    • 416 Posts
    I've setup a contact form, very similar to many others I've done before. However, this one will only submit after two tries.

    When I complete the form and press submit, it goes to the top of the form and displays all the data I just entered. Only after I press submit a second time, does it redirect to the designated thank you page and send the email out.

    I tried removing all the hooks except for email and removed the validation parameters, no change. The validation is working as expected.

    I'm thinking it's something related to the error placeholders or some cache issue.

    Any ideas about why this is happening?

    Here's my form:

    [[!FormIt?
    &hooks=`spam,email,redirect,FormItAutoResponder`
    &emailTpl=`emailsendto`
    &fiarTpl=`emailcc`
    &fiarToField=`email`
    &fiarFrom=`xxxxxxx.com`
    &fiarFromName=`[[++site_name]]`
    &fiarReplyTo=`xxxxxx.com`
    &fiar=`[[++site_name]]`
    &fiarSubject=`Subject - Contact from [[++site_name]] website`
    &emailSubject=`Subject - Contact from [[++site_name]] website`
    &emailTo=`xxxxxxx`
    &emailUseFieldForSubject=`1`
    &redirectTo=`80`
    &validate=`workemail:blank, 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">
    <input id="workemail" type="text" name="workemail:blank" value=""/>

    <label for="firstname"><span class="error">[[!+fi.error.firstname]]</span> </label>
    <input id="firstname" type="text" name="firstname" value="[[!+fi.firstname]]" placeholder="First Name" />


    <label for="lastname"><span class="error">[[!+fi.error.lastname]]</span> </label>
    <input id="lastname" type="text" name="lastname" value="[[!+fi.lastname]]" placeholder="Last Name"/>


    <label for="email"><span class="error">[[!+fi.error.email]]</span> </label>
    <input id="email" type="text" name="email" value="[[!+fi.email]]" placeholder="Email" />


    <label for="phone"><span class="error">[[!+fi.error.phone]]</span> </label>
    <input id="phone" type="text" name="phone" value="[[!+fi.phone]]" placeholder="Phone" />


    <label for="subject"><span class="error">[[!+fi.error.subject]]</span> </label>
    <input id="subject" type="text" name="subject" value="[[!+fi.subject]]" placeholder="Subject"/>


    <label for="text"><span class="error">[[!+fi.error.text]]</span> </label>
    <textarea id="text" name="text" rows="7" cols="45" placeholder="Message">[[!+fi.text]]</textarea>


    <div class="form-buttons">
    <input name="contactformsubmit" type="submit" value="Submit" />
    </div>
    </form>


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

      • 13428 ☆ A M B ☆
      • 1,031 Posts
      Hello Terry,

      maybe it is caused by name="workemail:blank", change it to name="workemail".

      BTW: FormItAutoResponder should never be executed by your call, because it has to work before the redirect
        • 36551
        • 416 Posts
        Thanks Jako

        I moved redirect to the end of that line so it follows FormItAutoResponder and changed the name of the field.

        No change, two submits still required.
          • 13428 ☆ A M B ☆
          • 1,031 Posts
          Should be a validating issue (but everything looks fine in my eyes). Could you deactivate/remove the &validate property and test it without/reduced validation?
            • 36551
            • 416 Posts
            If I remove the validation parameter complete from the call, but leave the snippets in place for each field (e.g. [[!+fi.error.email]]) the form will not submit at all. Just returns to the top of the page.

            If I complete the form it does submit on the first try.
              • 13428 ☆ A M B ☆
              • 1,031 Posts
              Have you closed the snippet call? This is missing in your example above.

              Is the snippet call in a richtext content field? Maybe you have html code/entities in your parameters.
                • 36551
                • 416 Posts
                Yes, the snippet call is closed.

                It is in a chunk which is placed in a richtext content field.

                Shouldn't it submit an empty form if there are no validation parameters?

                  • 13428 ☆ A M B ☆
                  • 1,031 Posts
                  It should submit … strange.

                  Is the chunk called cached or uncached?
                    • 36551
                    • 416 Posts
                     [[$contactform]]
                      • 18373 ☆ A M B ☆
                      • 3,141 Posts
                      One thing that comes to mind is that the post data might be getting lost the first time, perhaps due to a htaccess rule or something?

                      A submit to a non-www url for example will lose its submit value when the submission is then redirected to a domain including www. Different variations of that could be happening.

                      To see if that might be it, open your browsers dev tools and on the network tab make sure preserve log is on (Chrome). Then submit the form and see if there might be any redirects happening before it returning a response.
                        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.