We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40649
    • 40 Posts
    I'm struggling to get a formit contact form on the website I'm working on and need help. I'm new to modx and php. I have the latest version of both revo and formit installed. I also found a form example that I like and am trying to use, but have no idea how to use snippets or chunks and think my code might be off for that reason. Can someone look at my code below and steer me in the right direction? Also, I think I'm supposed to have an email chunk in there somewhere, but don't know where to put it. Thanks in advance!

    <div id="main-content">
    
    
    [[!FormIt?
       &hooks=`spam,email,redirect`
       &emailTpl=`MyEmailChunk`
       &emailSubject=`High Priority: Contact Form Submission from AmmoniaGauges.com`
       &emailTo=`[email protected]`
       &redirectTo=`2`
       &validate=`name:required,
          email:email:required,
          phone:required,
          subject:required,
          text:required:stripTags` 
    ]]
    
    <h1>Contact Us Today!</h1>
     </br>
    [[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]
     
    <form action="[[~[[*id]]]]" method="post" class="form">
        <input type="hidden" name="nospam:blank" value="" />
     
        <label for="name">
            Name: <input type="text" name="name" id="name" value="[[!+fi.name]]" />
    
            <span class="error">[[!+fi.error.name]]</span>
        </label>
        
    </br>
    <label for="phone">
            Phone:
    <input type="text" name="phone number" id="phone" value="[[!+fi.phone]]" />
            <span class="error">[[!+fi.error.phone]]</span>
        </label>
        
    </br>
     
        <label for="email">
            Email:
    <input type="text" name="email" id="email" value="[[!+fi.email]]" />
            <span class="error">[[!+fi.error.email]]</span>
        </label>
       
     </br>
       
        <label for="text">
            Questions/Comments: </br>  <textarea name="text" id="text" cols="55" rows="7" value="[[!+fi.text]]">[[!+fi.text]]</textarea>
            <span class="error">[[!+fi.error.text]]</span>
        </label>
     
        
        <div class="form-buttons">
            <input type="submit" value="Send Inquiry" />
        </div>
    
    
    </form>
    
    </div>


      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You might want to try this to start with http://rtfm.modx.com/display/ADDON/FormIt.Examples.Simple+Contact+Page

      Just create your email chunk; formit will fetch it when it's ready to send the email. That's what the emailTpl property is for.

      &emailTpl=`MyEmailChunk`
      [ed. note: sottwell last edited this post 14 years, 2 months ago.]
        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
        • 40649
        • 40 Posts
        I actually have been trying to follow that example, but don't know if I should create a new snippet or if the code as it is in my contact form is right. I have several "formit" snippets, but have no idea what to do with them... I'm very, very new to modx.

        I created a new chunk, but my form is still just refreshing the page when I hit submit.

        Here's the page: http://www.ammoniagauges.com/contactus.html

        Thanks for this and any other insights! smiley
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          In your form, you have
          <input type="text" name="phone number" id="phone" value="[[!+fi.phone]]" />


          In the snippet properties you have
          phone:required,


          They have to match. Plus the name attribute of a form field cannot have a space.
            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