Enable/Disable CFFORM Validation

Add comments

I have searched many different sites to find out how to disable client-side validation used in CFFORMs. First off, if you are looking to enable/disable validation in your Flash form, check out the following resource: http://www.asfusion.com/blog/entry/enabling-and-disabling-validation-in .

So, to start, here is my scenerio: I have a CFFORM with 2 different sections. The user can either select from an existing piece of equipment, or create a new one. If you haven't guessed by now, all the fields for creating a new piece of equipment are required and are validated on submittion of the form. The problem was, if the user selects an existing piece of equipment, they are still prompted to fill in the fields.

I dug through the generated Javascript to see what I could possibly alter to not require those fields. I was able to find the following:

if (window.ColdFusion) ColdFusion.required['custEquipMake']=true;

but go figure, setting that false did not change anything.

Here was my solution and a snippet of my form code:

... ...

When submitting the form, all of the validation is set in the onsubit() function ColdFusion automatically generates, but first, the onClick() function of my submit button executes. Let's take a look at that function:

var defaultOnSubmit = null; function checkEquipForm(form) { /* Don't require the fields if they are selecting an existing equipment piece */ if( $('custEquipment').getInputs('radio','equipChoice').find(function(radio) { return radio.checked; }).value == 1) { /* Backup the CF validation function */ defaultOnSubmit = form.onsubmit; /* Set my own custom 'onsubmit' function; to have no custom function, set this to null */ form.onsubmit = checkEquipFormOnSubmit; } else { /* Check to make sure the validation function was backed up (so we don't overwrite it with a null value) and then restore the function to the form */ if (defaultOnSubmit != null) { form.onsubmit = defaultOnSubmit;} } return true; }

I have a global variable defaultOnSubmit that I initialize to start. checkEquipForm() takes a parameter "form" that is... well, my form. The conditional statement checks to see which radio button is checked. If it is the top radio button, then the user has selected an existing piece of equipment so there is no need for validation. With that said, I store the onsubmit() function that is used for validation in a global variable. I do this because if the user closes out of my cfwindow and re-opens it, I need to have the ability to do validation just in case they change their mind, so I need to refer back to CF's validation function. I then set a new onsubmit() function that I wrote. If you do not wish to have a custom onsubmit() and just bypass validation, simply set this value to null. Moving down to the "else" condition.. if we reach this, this means that the user has selected the second radio button and we need to do validation. So, I then check to make sure my defaultOnSubmit variable is not null because if it were, then I would essentially be over-riding the validation function that I want to use.

I must admit, I have been starring at this code for 14 hours today, so if you do not understand something, please ask. I'm sure my explanation may have been a bit blurry in some places. I do not see how this will work for disabling validation on specific elements like you can do in Flash forms, but if I figure it out without re-writing the cfform.js file, I'll be sure to post it.

6 responses to “Enable/Disable CFFORM Validation”

  1. Johnwr Says:
    I didn't understand the concluding part of your article, could you please explain it more?
  2. wholesale sunglasses Says:
    One again, your idea is very good.thank you!very much.
  3. wholesale shoes Says:
    very good information you write it very clean. I'm very lucky to get this information from you.
  4. pu erh tea Says:
    Great article Thank you so much!
  5. foellainvacle Says:
    Guys, I need some help here folks I'm Looking to purchase TV Stands or TV Wall Units For a loft I'mclosing on. Can anyonegive me a good recommendation of where is the leadingdeal on these? I live in Newark and I heard that the big thing about these tv stands is the cost of shipping and installation. I also found this great article about wiring your entertainment center: http://www.helium.com/items/1577888-how-to-wire-your-home-entertainment-center thanks in-advance for all your help data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCABQAFADASIAAhEBAxEB/8QAHQAAAQMFAQAAAAAAAAAAAAAABwQFCAABAwYJAv/EAEwQAAECBAMDBQgKEgMAAAAAAAECAwAEBREGByEIEjETQVFhwSIyUnJzhZGxFBUWKEJicaKkshgjJSczNDc4RVN1gaGzwsPS06O04//EABYBAQEBAAAAAAAAAAAAAAAAAAABAv/EABwRAQEBAQACAwAAAAAAAAAAAAABEQISQSExUf/aAAwDAQACEQMRAD8AmXAO241FOz1VbEgmclRp5VJg4wC9ug+99qHXPSv8yAghLzFRldZaoTrPk5hSfUYXMYpxfK/i2K6+zb9XUXU+pUUqW6oTvMWEFw7M5m5kyv4LH2KE26aq+f6oXy+dua8uRu48rqreHNKX9a8ac81CJ1Fj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Lc4iXQsE67ylAgaX1/dDsvCj6DYMvX6fdGwewQlouUWaVVpsvUKVgqrzEnMo5Rl1ISgKSeBG8oQuRkTnG64pAwHVbi1yp1hI9JcsYl45t1ud2eySbo8jJ02ZVPTUwzOdyZRtupJmQ4b90FBHe81r9carJT0/PJcYmav7GaY3Q2pwK3QLbu6NxJPBI4+DG/I2ds6HOGB5oeNPyo9bsKGtmfOlfHCKG7+FVJXscMJzzEvVvsOnZcC5OJWT07qXz/AEQjnJdPIOOJrqHlpTcN7jgKuoXEFdrZfzlWSDh2TbseK6mzY+hRhQnZUzhX+jqMjxqkOxJh48nnf1sOwGd7OavEEH7jO6jy7MTkiJmyHldjbLzOOtIxNRHpeX9qFNtziO7l3VF1ogJWNCbA6cdOESzi1h//2Q== Rex
  6. Biallileab Says:
    It agree with you Looking to make extra money for your IT business? Try N-able network management

Leave a Reply

Powered by Mango Blog. Design and Icons by N.Design Studio