Need cfset "errorMsg" to display | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | | |
best answer - posted by acoder |
OK, from line 30-33, you have: - <cfif Len(Trim(errorMsg)) GT 0>
-
<cfset urlString = URLEncodedFormat(errorMsg)>
-
<cfset valueString = "name=#URLEncodedFormat(form.name)#&company=#URLEncodedFormat(form.company)#&email=#URLEncodedFormat(form.email)#&phone=#URLEncodedFormat(form.phone)#&comments=#URLEncodedFormat(form.comments)#">
-
<cflocation url="#cgi.HTTP_REFERER#?email_error=1&error_msg=#urlString#&#valueString#">
Change that to: - <cfif Len(Trim(errorMsg)) GT 0>
-
You have the following errors:<br>
-
<cfoutput>#errorMsg#</cfoutput>
-
Please correct them.
You could, of course, add some HTML/CSS to improve the display (position, colours, etc.)
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Need cfset "errorMsg" to display
You could use the information that's added to the URL to display the error messages on the next page that cflocation relocates to. You would check for url.email_error. If it's defined and set to 1, then there was an error and you could parse the remaining string to get the error messages.
Having said that, that would be one step too many. It would be better to display on the page where the errors are discovered during validation. To display, just use cfoutput.
| | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | re: Need cfset "errorMsg" to display Quote:
Originally Posted by acoder Having said that, that would be one step too many. It would be better to display on the page where the errors are discovered during validation. To display, just use cfoutput.
I have no doubt you are an expert at this, I am less than novice. I want to learn and do best from example.
Could you please show me what I need to do to use "cfoutput" in this situation.
Cheers,
confusedfusion
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Need cfset "errorMsg" to display
OK, from line 30-33, you have: - <cfif Len(Trim(errorMsg)) GT 0>
-
<cfset urlString = URLEncodedFormat(errorMsg)>
-
<cfset valueString = "name=#URLEncodedFormat(form.name)#&company=#URLEncodedFormat(form.company)#&email=#URLEncodedFormat(form.email)#&phone=#URLEncodedFormat(form.phone)#&comments=#URLEncodedFormat(form.comments)#">
-
<cflocation url="#cgi.HTTP_REFERER#?email_error=1&error_msg=#urlString#&#valueString#">
Change that to: - <cfif Len(Trim(errorMsg)) GT 0>
-
You have the following errors:<br>
-
<cfoutput>#errorMsg#</cfoutput>
-
Please correct them.
You could, of course, add some HTML/CSS to improve the display (position, colours, etc.)
| | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | re: Need cfset "errorMsg" to display
Thank you for your time on this; I will give it all a try and will for sure reply back whith the success I am confident you have shown me.
| | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | re: Need cfset "errorMsg" to display
I am trying this: - <cfif Len(Trim(errorMsg)) GT 0>
-
<p style="font:bold 12px Verdana, Arial, Helvetica, sans-serif; color:red;">You have the following errors:<br>
-
<cfoutput>#errorMsg</cfoutput>
-
Please correct them. </p>
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Need cfset "errorMsg" to display
You forgot the closing # sign: - <cfoutput>#errorMsg#</cfoutput>
| | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | re: Need cfset "errorMsg" to display
Thanks for catching that for me; I have a nightmare work inviroment here; not testing server; I have to make code changes and submit online forms to have the files "pushed" live from a ftp. So I was able to fix that before submitting the request. It makes my learnig curve shoot out into the heliosphere. I have to wait to see if my code works or not.
Again, thank you.
| | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | re: Need cfset "errorMsg" to display
The error msg worked great; it displayed and then after a few seconds it redirects to the home page, I used the back button once took me back to the displayed errors, second back took me to the form with the fields still filled out,
Can you show me a way to have the errors display and then instead of going to the home page, returning back to the form without clearing the fields?
Thank you,
C
| | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | re: Need cfset "errorMsg" to display Quote:
Originally Posted by confusedfusion Can you show me a way to have the errors display and then instead of going to the home page, returning back to the form without clearing the fields?
I found the "refresh" easy fix there, just changed it to the form URL; I guess the form will be blanked on the refresh but it should be fine, if the user is not filling in the blanks right then the error will tell them and they can try again.
I know I like forms that don't blank my entries on error but if mine is that way I'll just live with it.
Thanks for everything.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Need cfset "errorMsg" to display
How about a link back to the form (if the user doesn't know they should go back)? That'd be better than a refresh which might not give the user enough time to read all the errors. They can then change the fields and re-submit the form.
Another option is to use the same page for submission, but display the error messages and re-display the form with the fields filled in as input.
| | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | re: Need cfset "errorMsg" to display Quote:
Originally Posted by acoder Another option is to use the same page for submission, but display the error messages and re-display the form with the fields filled in as input. I like your suggestion of Opt2 but not sure how to get that to work.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Need cfset "errorMsg" to display
Instead of setting the form action to mailer.cfm, set it to the same page and put the code in mailer.cfm in the form page. Of course, at the top, it should check that if anything has been submitted, e.g. - <cfif isdefined("form.send_email")>
-
<!--- mailer code here --->
-
</cfif>
Then for the form, you can set all the values to empty initially, but when submit (with errors), set their values to the inputted values, e.g. for a text field: - <input type="text" ... value="<cfoutput>#phone#</cfoutput>">
That's the basic idea and there are other ways you could do this too. Also, if you just want a basic, quick easy solution, then the back link would be best.
| | Newbie | | Join Date: Mar 2009 Location: TEXAS
Posts: 15
| | | re: Need cfset "errorMsg" to display
That looks good, I may or may not go the "quick and easy" with a back button; It may not be good work habits on my part but at around 18K £ a year not going to go too much farther out to gets this page "done."
Thanks for the awesome expert information. I will rember it and will also answer what I can from time to time here at bytes.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Need cfset "errorMsg" to display
No problem. Since you're new to Coldfusion, perhaps you'll find these tutorials useful. Also, have a look at the Adobe website for tutorials, guides and documentation.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|