We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39025
    • 21 Posts
    Here's what I would like to do, and forgive me but I am a designer not a programmer.

    I would like to place two hidden fields in a form, "firstname" and "lastname" as an example, on submit, loop through the form for values in those fields, if values exist, don't submit.

    Using formit currently to handle submissions.

    Can someone help?
      • 3749
      • 24,544 Posts
      http://rtfm.modx.com/display/ADDON/FormIt.Using+a+Blank+NoSpam+Field

      A word of warning, though. If you use "firstname" or "lastname" some people with password managers like Roboform and LastPass are not going to be able to submit anything because the password manager will try to be helpful by filling in those fields. wink

      Also, some spambots are smart enough not to fill in a hidden field.
        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
        • 39025
        • 21 Posts
        Awesome, all wrapped up, worked, thank you.

        One last question, how would I get the page to anchor to the form if it's middle of page? Right now it reloads the page with errors, which is great obviously, but user has to scroll down to see the errors.

        I know how to do anchors, but how do I get the redirect to anchor down the page?
          • 39025
          • 21 Posts
          Actually I lied... It's validating, but now it's not submitting, here's what I have:

          [[!FormIt?
             &hooks=`spam,email,redirect`
             &emailTpl=`ContactMailer`
             &emailTo=`[email protected]`
             &emailSubject=`Message from Someone`
             &redirectTo=`34`
             &validate=`Name:required,
                Email:email:required,
                Phone:required,
                Message:required:stripTags`
          ]]


          [[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]
          
          <form id="content_right_form" name="content_right_form" action="[[~[[*id]]]]" method="post" class="content_right_form">
            <input type="hidden" name="SC:blank" value="" />
          
            [[!+fi.error.Name]]
            <input id="Name" name="Name" type="text" value="Name" onfocus="if (this.value == 'Name') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Name';}" class="textfield" />
          
            [[!+fi.error.Phone]]
            <input id="Phone" name="Phone" type="text" value="Phone" onfocus="if (this.value == 'Phone') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Phone';}" class="textfield" />
          
            [[!+fi.error.Email]]
            <input id="Email" name="Email" type="text" value="Email" onfocus="if (this.value == 'Email') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Email';}" class="textfield" />
          
          	<select name="LocationInterest" value="[[!+fi.LocationInterest]]">
                      <option value=" ">Location Interested In</option>
                      <option value="Emerson" [[!+fi.LocationInterest:FormItIsSelected=`Emerson`]]>Emerson Pointe</option>
                      <option value="Lakeside" [[!+fi.LocationInterest:FormItIsSelected=`Lakeside`]]>Lakeside Village Townhomes</option>
                      <option value="Sunrise" [[!+fi.LocationInterest:FormItIsSelected=`Sunrise`]]>Sunrise Pointe</option>
                      <option value="Sol" [[!+fi.LocationInterest:FormItIsSelected=`Sol`]]>Sol Vista Townhomes</option>
                      <option value="Stevens" [[!+fi.LocationInterest:FormItIsSelected=`Stevens`]]>Steven's Plantation</option>
                      <option value="Woodbridge" [[!+fi.LocationInterest:FormItIsSelected=`Woodbridge`]]>Woodbridge on the Green</option>
              </select>
            <textarea id="Message" name="Message" class="textarea" onfocus="if (this.value == 'What can we do to help?') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Additional Info?';}">Additional Info?</textarea>
            <input type="submit" class="submit" value="Send" />
          </form>


          Any ideas why it would stop submitting and redirecting, it worked fine before I added the spam check stuff.
            • 3749
            • 24,544 Posts
            I almost never use FormIt. Hopefully, someone with more FormiIt experience will step up.
              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
            • Are you sure that is the field names exactly? Usually field names are all lower-case.
                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
                • 39025
                • 21 Posts
                Yes, sure.

                The form worked correctly, redirected, etc, before I added the spam stuff and validation. Now it validates correctly, but doesn't submit.

                  • 39025
                  • 21 Posts
                  So i took this part out: [[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]

                  and it works fine, I'm not sure why.

                  Still looking for any way to anchor the page back down to the form if error exists?

                  Thanks,
                    • 3749
                    • 24,544 Posts
                    You should be able to use the anchor in the form's action:

                    <form action="[[~[[*id]]]]#MyAnchor" />
                      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
                      • 39025
                      • 21 Posts
                      Quote from: BobRay at Jan 31, 2013, 06:02 AM
                      <form action="[[~[[*id]]]#MyAnchor">
                      </form>

                      Thanks Bob, perfect.