We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34174
    • 67 Posts
    Hi folks...what's wrong with my code? FormIt doesn't work. Leaving the fields blank just reload the form, without displaying a validation error. Entering all the fields also just reloads the form and clears the fields. No error or success message. No saved form in the FormIt table.

    Thanks in advance.


    <!-- FORMIT begins ======================================================== -->
    
          [[!FormIt?
            &hooks=`spam,email,FormItSaveForm`
            &submitVar=`contact-submit`
            &spamEmailFields=`workemail`
            &emailTpl=`contact-form-email-en.tpl`
            &emailSubject=`[CONTACT FORM] - [[+your_name]]`
            &emailTo=`[[++site.client.email]]`
            &successMessage=`<div class="alert alert-success">We've received your info and will contact you as soon as possible.</div>`
            &validationErrorMessage=`<div class="alert alert-danger">Please check the fields below. One or more may be invalid or missing.</div>`
            &DISABLEDredirectTo=`98`
            &errTpl=`<div class="alert alert-danger">[[+error]]</div>`
            &formName=`CONTACT`
            &validate=`workemail:blank,
            your_name:required,
            email:email:required,
            comment:required`
          ]]
    
    
          <!-- start section -->
          <section class="section section--no-pt">
            <div class="container">
              <div id="send_message"><br><br><br><br><br><br></div>
              <h4 class="h2">Send Message</h4>
    
              [[!+fi.successMessage:notempty=`[[!+fi.successMessage]]`]]
    
              [[!+fi.error_message:notempty=`<div class="alert alert-danger" >[[!+fi.error_message]]</div>`]]
              [[!+fi.validation_error_message]]
              [[!+fi.validation_error]]
    
              <form action="[[~[[*id]]]]#send_message" method="post">
                <div class="row">
                  <div class="col-md">
                    <label class="input-wrp">
                      <input class="textfield" type="text" id="your_name" name="your_name" placeholder="Your name" value="[[!+fi.your_name]]" />
                    </label>
                    <span class="help-block">[[!+fi.error.your_name]] </span>
                  </div>
    
                  <div class="col-md">
                    <label class="input-wrp">
                      <input class="textfield" type="text" id="email" name="email" placeholder="E-mail" value="[[!+fi.email]]" />
                    </label>
                    <span class="help-block">[[!+fi.error.email]] </span>
                  </div>
                </div>
    
                <label class="input-wrp">
                  <textarea class="textfield" id="comment" name="comment" placeholder="Comment">[[!+fi.comment]]</textarea>
                </label>
                <span class="help-block">[[!+fi.error.comment]] </span>
    
                <input type="text" id="workemail" name="workemail" value="">
    
                <input class="custom-btn primary submit-button" type="submit" name="contact-submit" value="Send »">
              </form>
            </div>
          </section>
          <!-- end section -->
    
    
    
      • 17301
      • 932 Posts
      Nothing seems to be wrong - I just tried it on a blank tpl and replaced the emailTo and the validation works fine, the form posts and saves when filling it out.

      You may have some JavaScript blocking the form from submitting? Particuarly if you're using a scroll to script of some kind that is listening for a hashtag id, as you have one in your formit action.
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 30585
        • 833 Posts
        Few things to try:

        1 - Start with fewer hooks and scale up. Ex: start with the spam hook, then add the next one if the spam hook works when called alone, etc.
        2 - Call the FormItSaveForm hook before the email hook
          A MODx Fanatic
          • 34174
          • 67 Posts
          Thanks folks - seems it is indeed the JS. Original site is a template and the JS is all compressed....so...hurdles...

          Thanks again.