Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cflocation

Status
Not open for further replies.

AlwaysWilling

Programmer
Dec 29, 2005
51
US
Hello. In the past when I wanted to pre-populate the form fields the user entered I did <cfif isdefined("FORM.fieldName")>#FORM.fieldName#</cfif>, but I got to know that this doesn't work when you use cflocation tag. So how else I can re-populate the user's answers on the form?

My scenario is:
1. user fills out form
2. user submits form (leaving one required field blank)
3. i do server-side validation, like check if the email field is in an email syntax, etc. if the additional criteria fails i do a cflocation back to the form.

And, its here that I want the fileds to be populated. Is this possible? How?
 
easy!

if during the form validation there is an error, save the form values to session scopes.

so if input name="firstName" save it to session.yourform.firstName = form.firstname

so when you cflocation back to the form you can
input name="firstname" value="#session.yourform.firstname#"

cfparam the session.yourform.firstName default="" so that the form doesn't error on the first view.

then, at the bottom of the form page use structdelete(session,"yourform") to easily delete the session variables for the form handling.

if that does not make sense, i can possible get you code samples when I get home.



 
i got an even easier idea: form submits to itself

the code will do a simple test -- validate the values, and if they aren't all okay, display the same form! and if they are okay, don't display the form, process it instead

see? piece o' cake

all of these coding shenanigans just to get around a stupid CFLOCATION

i've said it before, CFLOCATION is evil, and if you didn't have the CFLOCATION tag, what would you do? you'd find a better way to do things

sorry for the soapbox, i'll be quiet now...

r937.com | rudy.ca
 
hush up, you. :)

whether the form submits to itself or not, there is still a substantial amount of coding to make error messages work user-friendly-ish, and form validation, etc...

most of what i mentioned I would do on a self-submiting form, or a formpage / actionpage. The session storage is espacially usefull on multi-page forms where users can backtrack to previous steps to change info.



 
self-submiting ... blah blah ... formpage / actionpage... blah blah ... session ... blah blah ... multi-page forms ... blah blah ... backtrack ...

c'mon, admit it, you just like sessions, dontcha, and can't resist another opportunity to use them ...

:) :)

(actually, i'm just funnin' with ya)

r937.com | rudy.ca
 
I dream in sessions.


anyways, AlwaysWilling has a few suggestions now, we can stop messing up his post.

 
Thanks a lot guys for all the suggestions. I use to do the form submission to itself, but that just makes the page longer since you at the top you have your cfcode wrapped in CFIF's. I also thought about the session thing, and that seems quite doable (as does r937's suggestion).

For now, I use some JS code for the smaller forms, for the larger ones, I have the "required field" message at top, the questions themselves are in bold font style.

Is there a precendence in using one over the other in relation to speed and execution of code?
 
I use to do the form submission to itself, but that just makes the page longer since you at the top you have your cfcode wrapped in CFIF's.
not exactly -- the only thing that should be subject to CFIF is whether the form was actually submitted or not, and i always do this by testing for the presence of the submit button in the FORM structure using CFPARAM


<CFPARAM NAME="form.pushme" DEFAULT="^^nope^^">
<CFIF form.pushme IS "^^nope^^"
<!--- form not submitted, set values to default --->
<CFELSE>
<!--- form submitted, set values to submitted,
then validate them --->
</CFIF>


r937.com | rudy.ca
 
I do that too. I meant further validation inside the "if form is submitted". Like is phonenumber numeric, does zipcode match state, is email valid, etc.

I do:
<cfif isdefined("FORM.SubmitButtonName") and FORM.field1 NEQ "">
...
<cfelse>
ERROR WILL ROBINSON, ERROR!
</cfif>
 

further validation inside the "if form is submitted"

yes, i guess so

combine two pages (form and action) into one page, which will be, um, as large as the two pages separately were, with one über-CFIF to separate the two chunks of code...

sounds pretty easy to me ;-)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top