We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28215
    • 4,149 Posts
    splittingred Reply #1, 16 years ago
    This is an auto-generated topic for FormIt 1.2.1-pl by splittingred.

    Brief Description:

    Automatically validate, parse and email forms. Redirect to thank you pages. Add your own hooks as Snippets to handle forms dynamically. Validate with custom Snippets. All is possible in FormIt, the new form processing Snippet for MODx Revolution 2.0.
    New in 1.2.1

    • Added recaptchaTheme property, which allows theming of reCaptcha hook

    New in 1.2.0

    • Added preHooks property to allow for custom snippets to pre-fill fields
    • Added clearFieldsOnSuccess property to clear fields after a successful form submission without a redirect
    • Added customValidators property to FormIt snippet to restrict custom validators to only specified validators to prevent brute force snippet loading. All custom validators' names must now be passed into this property.
    • Allow placeholders of fields in all email properties
    • Added fiValidator::addError for easier error loading for custom validators
    • Added German translation


    See the Official Documentation here:http://rtfm.modx.com/display/ADDON/FormIt
      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
      • 25357
      • 92 Posts
      Shazaaam! smiley again this is v. 1.2.1 (move to that thread if helpful)

      - All errors in list context at top of form
      - set default values while maintaining form state on error

      What hung me up was errTpl, was expecting it to be a chunk. I mean. . . Tpl . . . yeah. smiley

      Small version of form:

      <form method="post" action="[[~[[*id]]]]" id="contact-form">
      <ul id="formit-errors" style="display:none;">[[$formit-errorlist]]</ul>
      <p><label for="fname">First Name:</label><span class="required">*</span> 
      <input class="txt" type="text" id="fname" name="fname:required:stripTags" size="35" value="[[+fi.fname]]"></p>
      <p><label for="emailaddr">Email Address:</label><span class="required">*</span> 
      <input class="txt" type="text" id="emailaddr" name="emailaddr:email:required:stripTags" size="35" value="[[+fi.emailaddr]]"></p>
      <p><input type="submit" class="graphic-button" value="Submit"></p>
      </form>
      
      [[!FormIt? 
      &preHooks=`loadInitialValues` 
      &hooks=`email,redirect` 
      &emailSubject=`Visitor Inquiry from Your Site` 
      &emailTpl=`smallFormReport` 
      &errTpl=`<li>[[+error]]</li>` 
      &emailTo=`[email protected]` 
      &redirectTo=`123`]] 


      Note errTpl is a list for semantic considerations . . .

      formit-errorlist

      [[+fi.error.fname]]
      [[+fi.error.emailaddr]]

      loadInitialValues

      <?php
      $ph = Array(
      	'fi.fname'	=> 'Your First Name',
      	'fi.emailaddr'	=> 'Your Email Address'
      );
      foreach ($ph as $fld=>$def) {
      	$modx->setPlaceholder($fld,$def);
      }
      return true;
      ?>


      At first I had it as a standalone at the top of the form as suggested, with this

      foreach ($ph as $fld=>$def) {
      if (! $modx->getPlaceholder($fld)) {
      $modx->setPlaceholder($fld,$def);
      }
      }

      But of course since formit hasn’t yet executed, the placeholder would always not exist at that point so it would always add the default. As a prehook it does both, adds the default fields (which is still a STUPID idea) and maintains state on error.

      The only thing I DON’T like is I have the errors hidden, if innerHTML != ’’ I use JS to display them. That’s gotta go. smiley

      Now I just need to do a dynamic output for a response instead of a redirect, kinda’ liking that session idea. smiley
        • 3749
        • 24,544 Posts
        Quote from: rocknbil at Sep 12, 2010, 04:14 PM

        What hung me up was errTpl, was expecting it to be a chunk. I mean. . . Tpl . . . yeah. smiley

        The correct term would be "Tpl chunk." wink

        Glad you got it working.
          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
          • 25357
          • 92 Posts
          <sigh> So this was working, developed out the rest of the site, ran everything through the validator (which fails with one error due to <ul></ul> without error . . . no big) and now for some reason all my errors are empty. Nothing else changed. Any ideas as to the cause?

          EDIT: Solved, sorta. And something had changed I’d forgotten.

          For a time I thought there was a conflict between named "email" and the email validation,

          email:email

          so I’d changed my email field to emailaddr and not updated in error-template. Since I was using Javascript validation, the only way to tell was disable JS and submit with empty fields.

          Which leads to another (small) problem.

          For required fields I’m getting

          <li>This field is required.</li>
          <li>This field is required.</li>

          The logic being, of course, the samples have those as spans by the fields. Which they are not. So I’m off to see if I can get

          <li>The [[+email]] field is required.</li>
          <li>The [[+phone]] field is required.</li>

          without hacking the code.

          EDIT 2: Is this possible without hacking up the lexicon includes?

          $_lang[’formit.field_required’] = ’The ’ + $fields[’field’] + ’ field is required.’;

          Or a placeholder, etc. . .
            • 3749
            • 24,544 Posts
            Just go to System -> Lexicon Management.

            Navigate to the FormIt namespace then the default topic and change that language string’s value. Your change should survive upgrades.
              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
              • 31915
              • 1 Posts
              Hi everyone.

              I’ve figured out how to pre-load the values of my form by creating a snippet. I was looking for some way to get the pre-loaded values to disappear when the user clicks on the field. Currently the user of the form would have to delete the pre-filled information before submitting. I think it would be much better if they didn’t have to delete the info.

              Any help in pointing me to a thread with an answer or assistance would be appreciated.

              Thanks!
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                That has to be done with Javascript. There are dozens of scripts and libraries with functions to do that. Here’s a few.

                http://plugins.jquery.com/project/clearFields
                http://plugins.jquery.com/plugin-tags/remove-value
                  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
                  • 6902
                  • 126 Posts
                  I’m trying to make a custom hook to be used in multiple forms that needs form-specific data (in this case, the names of the fields it needs to process in whichever form is using it). I would prefer to pass that data to it via a FormIt snippet element.

                  Example:
                  [[!Formit?
                    &hooks=`myHook`
                    &myVar=`something`
                  ]]

                  How can I get to $myVar from the myHook snippet? ...or is this even possible?
                    • 28215
                    • 4,149 Posts
                    debussy:

                    $scriptProperties['myVar'];
                    

                      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                      • 6902
                      • 126 Posts
                      grin Awesome! Thanks! grin