Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problems with Cold Fusion Forms

New Here ,
Mar 20, 2008 Mar 20, 2008
Hey Everybody -

Pretty new to these forums and cold fusion in general. I created a number of forms in cold fusion for a school. They sign up for classes and when they fill out ALL text fields they successfully submit the form and they see a success page. Sounds great right? well kind of.

If a user doesnt fill out the entire form, and submits it gives them an error with coldfusion errors. So I am faced with a few choices. I can either: have the form forward them to an error page instead of the coldfusion error, or if there's a way I can fill in the null values so that there isnt a problem with nulls. I want to have validation but I want it in a seperate page since I dont have the room to add errors in the form itself.

Any help would be great. Thanks in advance.
TOPICS
Getting started
833
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 20, 2008 Mar 20, 2008
You need to validate your form fields either in server side via CF or in client side via JavaScript etc.

Here is the official documentation:
http://livedocs.adobe.com/coldfusion/7/htmldocs/00001381.htm

There is also a nice tutorial about form usage.
http://www.adobe.com/devnet/coldfusion/articles/richforms_02.html


I also would suggest to check jQuery client side form validation in the following link.

http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 20, 2008 Mar 20, 2008
Oguz.Demirkapi wrote:
> You need to validate your form fields either in server side via CF or in client
> side via JavaScript etc.

it is not either / or. you should ALWAYS validate form data on the
server. you can also use client-side validation to make it more
user-friendly, but never rely on it to validate your data. validate on
the server. for one, if a client has js turned off in their browser your
client-side validation flies out the window...

i have not checked the links Oguz provided, but basic concept of form
validation is:
<cfparam> your form vars on the action page to default values - that way
if a user does not fill in a field, it will default to the value you set
in cfparam for it.
text fields ALWAYS have a value - an empty string '' if it has not been
filled in. checkboxes and radio button, if not checked, are not
submitted with the form. so cfparam those always.
drop-down select lists are treated differently by different browsers.
some preselect the first element in the list, others set the value of
the select to -1 if nothing is selected. you can control default
selection in the list with seslected="selected" attribute in the field.
it is useful to cfparam these as well...
if you want the user to be able to try submitting the form, show errors
on next page, then return to the form and have their previously entered
data pre-filled for them, use session-scope vars to store form data:
just copy your form to session var on your action page. make sure
sessions are enabled in cf administrator and in your application.cfm/cfc

hth



Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 20, 2008 Mar 20, 2008
I think it was a wrong expression. :)

You have to validate always in server side. But client side validation is just good for usability and not required for validation process.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2008 Mar 20, 2008
Use cfform. Typical fields like cfinput, cfselect and cftextarea have attributes that enable you to get Coldfusion to do your clientside validation for you. Here follows a rough sample to whet your appetite:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 21, 2008 Mar 21, 2008
Before you do any of that, make sure you understand the requirements of the app you are writing. Specifically, determine whether or not it is necessary to fill in every text box.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2008 Mar 21, 2008
Dan Bracuk wrote:
Before you do any of that, make sure you understand the requirements of the app you are writing. Specifically, determine whether or not it is necessary to fill in every text box.

I assumed that that is implicit, as Tec28 says, "when they fill out ALL text fields they successfully submit the form".



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 26, 2008 Mar 26, 2008
I'm wondering, if by chance, that you have a checkbox or radio button on your submit page. If so, this may be why it's blowing up. If they don't have a response, the target page won't see the form. You have to cfparam those...

<cfparam name="form.radioButtonA" default="0" type="any">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2008 Mar 26, 2008
LATEST
I always do ALL my form validations with a client-side JS **and** with server-side CF.

I don't use <cfform>, I know <cfform> is dependant on the java version the user has installed on their end. I know I came across quite a few issues where on one machine the <cfform> worked fine, and on another it konked out.

Anways, this is one of my most basic forms:
=============================================
PAGE1.cfm
<html>
<head>

<script>
function validate() {
var IA = document.ContactUs;
var errorMSG = "";

if(IA.FullName.value == "") {errorMSG += "Full Name\n";}
if(IA.Email.value == "") {errorMSG += "Email\n";}

if(errorMSG != "") {
alert("The following fields are required:\n\n" + errorMSG);
return false;
}
}
</script>
</head>

<body>
<form name="ContactUs" action="page1_x.cfm" method="post" onSubmit="return validate();">
<table>
<tr>
<td align="right">Name: </td>
<td align="left"><input type="text" name="FullName" maxlength="50" size="25"></td>
</tr>
<tr>
<td align="right">Email Address: </td>
<td align="left"><input type="text" name="Email" maxlength="50" size="25"></td>
</tr>
<tr>
<td align="right">Comments: </td>
<td align="left"><textarea name="Comments" cols="20" rows="5" id="comments"></textarea></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="SubmitContact" value="Submit">
<input type="reset" name="Reset" value="Reset">
</td>
</tr>
</table>
</form>
</body>
</html>
=============================================

=============================================
page1_x.cfm
<cfif isdefined("FORM.SubmitContact") and FORM.FullName NEQ "" and FORM.Email NEQ "">
<!--- is all is OK, do whatever it is you want to do. --->

<cfelse>
<!--- if the submit button was no clicked, fullname and email (required fields) not filled out, send them back to the form --->
<cflocation url="page1.cfm?status=1" addtoken="no">
</cfif>
=============================================

Now, there is sooooo much more you can here for a full blown error-proof script. You can also check if the e-mail is a valid e-mail (server side), and if the field is a numeric field (like zip code, phone number, etc) then check if that field is valid, etc.

This is just a run-of-mill simple form and validation submission using both client-side JS and server-side code.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources