For Adobe ColdFusion application servers How do I force a form to reload without being validated?

Sometimes, you might want to change the format of a form as a visitor enters data into it. For example, a choice in one form field may cause other fields to appear or disappear. For whatever reason, you want TerraForm to rebuild the form without validating the visitor's data and without losing any of it.

TerraForm uses a hidden field at the bottom of your form to record the form's status. The field name is the same as your form name, so if your form is called editUser then that's what the field will be called too. It will normally contain the value form . When a form is submitted with this status, TerraForm knows that it should try to validate it. Since you want to stop TerraForm from validating, you need to change this value to refresh.

Use the following JavaScript code to cause your form to be reloaded without validation:

document.[myFormName].[myFormName].value = 'refresh';
submit()

where [myFormName] is your form's name. Your JavaScript needs to be associated with a particular browser event that causes the form to require refreshing. This could be any event such as onChange or onClick. Let's assume our form is an order form that needs to reload whenever the quantity ordered changes. The form name is orderForm. Here is our field:

<cf_terrafield
  name="quantity"
  datatype="integer"
  required="yes"
  min="0"
  max="99"
/>

We add the following attribute:

onChange="document.orderForm.orderForm.value = 'refresh'; submit()"

So the field looks like this:

<cfmodule
  template="#terrafield#"
  fieldname="quantity"
  datatype="integer"
  required="yes"
  min="0"
  max="99"
  onChange="document.orderForm.orderForm.value = 'refresh'; submit()"
/>

That's all you need to do — TerraForm takes care of the rest!

A sample is available for download in the Code Gallery.

No comments yet