Jump to content

Form Validation


vchris

Recommended Posts

I am working on an app that I can't change too much. The way the form validation work is with hidden input fields.Here's what I mean:

<input type="Hidden" name="company_required" value="Company Name is a required field">

The problem is that this validation method validates upon any submit button being clicked. In my form I have a 2 submit buttons and I can't get rid of 1. Is there some sort of option or attribute to this sort of form validation for it to only validate when a specific submit button is pressed?

Link to comment
Share on other sites

interesting, but I am not sure i can completely or directly answer it.If you are using built in ColdFusion validation, then you are stuck with their server side written javascript - which is good for simple things but very restricting for advanced validation.Given the fact that the validation is using hidden fields (never heard of that), it would seem that you are using a developer written validation script. So, looking at each submit button should tell you something. If, there is not a "onclick" attribute being used or if there is and both buttons are calling the same script, then the script is doing all the conditional logic. So, you might have to modify that to where you would have two scripts or at least one with two distinct functions (versus one). Then, the "onclick" attribute for each button would be unique to the button being used.Does this help any?

Link to comment
Share on other sites

This should help you understand what I mean http://livedocs.macromedia.com/coldfusion/...cs/00001385.htmThere is no onclick it's all done with CF because of the _required in the hidden field.Here's how it works. I have an input and a matching hidden input except I've added _required to the name and the value is the error displayed to the user. Upon form submission, CF will validate all fields that have a matching hidden field. The problem is when I add another submit button for another event. I cannot use javascript for that other button I've added. The point of that button is for users that do not support JS. Basically I have a drop down and with javascript enabled it makes a certain number of text field appear onchange and without javascript, you click a refresh button which reloads the page and makes the text fields appear.

...<input type="text" name="textinput" /><input type="hidden" name="textinput_required" value="textinput is required." /><input type="submit" name="submit" value="submit" />...

Link to comment
Share on other sites

Can you use two different forms? One form for the dropdown menu and another form for the rest of the inputs and put one submit button in each form? If you click the submit button in one form, do the inputs from the other form get submitted to the server?EDIT: I looked around a bit - as I'm sure you're already aware, I don't know lick about CF - and came across this link:http://cfdj.sys-con.com/read/42040.htmThe last paragraph on the page reads:

When you name submit buttons, you treat them as any other form field. Listing 12 demonstrates how to determine which submit button was clicked. The code <CFIF FORM.Operation IS "Update"> checks to see if the Update button was clicked, and <CFELSEIF FORM.Operation IS "Delete"> checks to see if Delete was clicked, but only if Update was not clicked.
If that's the case, maybe you could name your form submit button "Submit" and the page refresh button "Refresh" and use that funky looking <CFIF> tag to see if "Refresh" was clicked. Then, maybe, you could look at the value of your dropdown and reload the page with some new value in the query string (e.g. mypage.cfm?item=4).
Link to comment
Share on other sites

I cannot have 2 forms or else when the user submits the form only 1 form will be submitted (missing fields). I don't use querystrings for this page. As soon as the page reloads (any submit clicked) it will validate it so even if I have a <cfif> for the refresh button it will still validate first.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...