We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26903
    • 1,336 Posts
    When a required field fails validation cos its not filled in an error message appears but the form is cleared, meaning the user has to fill the whole form in again. Can Formit be configured to not do this.
      Use MODx, or the cat gets it!
    • I'd like to know how to do this too... writing a custom Formit Validator can return a true or false, but I don't see how to filter and return a value that should repopulate the form. It's much more secure to nuke the value on failed validation, but as you pointed out, it's not convenient.
        • 11449
        • 28 Posts
        Bump, this is a badly needed feature. Is there seriously no way of doing this?
        • I think you might be able to do it... look at the core code in core/components/formit/model/formit/fihooks.class.php

          The relevant lines starting around 136:

          /* custom snippet hook */
          $properties = array_merge($this->formit->config,$customProperties);
          $properties['formit'] =& $this->formit;
          $properties['hook'] =& $this;
          $properties['fields'] = $this->fields;
          $properties['errors'] =& $this->errors;
          $success = $snippet->process($properties);


          Looks like any custom hook validator gets passed a reference to the formit object, so you should be able to set field values inside your validator function, probably just by using the "setValue" method:

          $hook->setValue('my_field','filtered value');


          That's worth a try...
            • 11449
            • 28 Posts
            Ok I figured out a way using formItRetriver heres how you do it:

            1) Make sure you have &store=`1` set on your FormIt snippet call
            2) Place a formItRetriver snippet call after the formit one.
            3) add a
            value="[[+fi.nameofyourinput]]"
            to each input in your form

            Now when validation fails and the page is refreshed, formItRetriver will populate the form with the previously filed data. Below is my example incase it can help:

            [[!FormIt?
            	&hooks=`recaptcha,spam,email`
            	&emailTpl=`EmailTemplate`
            	&emailTo=`[email protected]`
            	&emailUseFieldForSubject=`1`
            	&submitVar=`go`
            	&store=`1`
            	&successMessage=`Thank you for your communication.`
            	&successMessagePlaceholder=`fi.successMessage`
            	&errTpl=`
            <small>[[+error]]</small>`
            	&validate=`name:required, email:email:required, subject:required, message:required:stripTags`
            ]]
            [[!formItRetriver]]
            <form class="contact" action="[[~[[*id]]]]" method="post" id="contactform">
              	<input type="hidden" name="nospam:blank" value="" />
              	<div class="clearfix forminfo">
              		[[!+fi.error_message:notempty=`<p><span class="label important">[[!+fi.error_message]]</span></p>`]]
            	  	[[!+fi.successMessage:notempty=`<p><span class="label success">[[!+fi.successMessage]]</span></p>`]]
              	</div>
            	<div class="clearfix">
            		<label for="name">Your Name[[!+fi.error.name]]</label>
            		<div class="input">
            			<input class="xlarge" id="name" name="name" size="30" type="text" value="[[+fi.name]]"/>
            		</div>
            	</div>
            	<div class="clearfix">
            		<label for="f-email">Your Email[[!+fi.error.email]]</label>
            	        <div class="input">
            	        	<input class="xlarge" id="email" name="email" size="30" type="text" value="[[+fi.email]]" />
            		</div>
            	</div>
            	<div class="clearfix">
            		<label for="f-subject">Subject[[!+fi.error.subject]]</label>
            		<div class="input">
            			<input class="xlarge" id="subject" name="subject" size="30" type="text" value="[[+fi.subject]]"/>
            		</div>
            	</div>
            	<div class="clearfix">
            		<label for="f-message">Message[[!+fi.error.message]]</label>
            		<div class="input">
            			<textarea class="xlarge" id="message" name="message" rows="5">[[+fi.message]]