473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Need cfset "errorMsg" to display

Not sure how many form submissions that have been lost over the years before I started but the company has a contact form that the required fields when validation fails the error message is going into the URL string on a refresh of the form page.

I am very green on CF and CFM files and have this code below; I need to help for the error messages to "pop up" in a new window or display on the body of the page so anyone filling out the form knows that an error occurred with the entry trying to be submitted.

Any help would be awesome!


mailer.cfm: (VALIDATE/SEND)

Expand|Select|Wrap|Line Numbers
  1. <META HTTP-EQUIV="Refresh"
  2. CONTENT="5; URL=http://whoscalling.com/index.php"> 
  3.  
  4.  
  5. <cfif IsDefined('form.send_email')>
  6.     <cfset errorMsg = ''>
  7.  
  8.     <cfif Len(Trim(form.name)) EQ 0>
  9.         <cfset errorMsg = errorMsg & '- Please enter your name<br/>'>
  10.     </cfif>
  11.     <cfif Len(Trim(form.email)) EQ 0>
  12.         <cfset errorMsg = errorMsg & '- Please enter your email address<br/>'>
  13.     <cfelseif form.email DOES NOT CONTAIN '@' OR form.email DOES NOT CONTAIN '.'>
  14.         <cfset errorMsg = errorMsg & '- Please enter a valid email address<br/>'>
  15.     </cfif>
  16.     <cfif Len(Trim(form.comments)) EQ 0>
  17.         <cfset errorMsg = errorMsg & '- Please enter your comments or questions<br/>'>
  18.     </cfif>
  19. <cfif Len(Trim(form.phone)) EQ 0>
  20.         <cfset errorMsg = errorMsg & '- Please enter 3 digit area code<br/>'>
  21.     </cfif>
  22. <cfif Len(Trim(form.phone2)) EQ 0>
  23.         <cfset errorMsg = errorMsg & '- Please enter the first three numbers of your phone number<br/>'>
  24.     </cfif>
  25. <cfif Len(Trim(form.phone3)) EQ 0>
  26.         <cfset errorMsg = errorMsg & '- Please enter the last four numbers of your phone number<br/>'>
  27.     </cfif>
  28.  
  29.  
  30.     <cfif Len(Trim(errorMsg)) GT 0>
  31.         <cfset urlString = URLEncodedFormat(errorMsg)>
  32.         <cfset valueString = "name=#URLEncodedFormat(form.name)#&company=#URLEncodedFormat(form.company)#&email=#URLEncodedFormat(form.email)#&phone=#URLEncodedFormat(form.phone)#&comments=#URLEncodedFormat(form.comments)#">
  33.         <cflocation url="#cgi.HTTP_REFERER#?email_error=1&error_msg=#urlString#&#valueString#">
  34.     <cfelse>
  35.         <cfmail to="#form.to_email#" from="#form.email#" subject="#form.subject#">
  36. An email has been submitted to learn more about FleetQUEST360 from the following person:
  37.  
  38. Name: #form.name#        
  39. Company: #form.company#
  40. Email: #form.email#
  41. Phone: #form.phone# #form.phone2# #form.phone3#
  42.  
  43. Comments: #form.comments#
  44.         </cfmail>
  45.         <cflocation url="http://www.whoscalling.com/ThankYou_fleetquest360.htm">
  46.     </cfif>
  47. <cfelse>
  48.     <p style="font:bold 12px Verdana, Arial, Helvetica, sans-serif; color:red;">You do not have access to view this page.</p>
  49. </cfif>


FORM:

Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="to_email" value="incomingleads@xxx.com">
  2.                     <input type="hidden" name="subject" value="Sales Support">
  3.  
  4. <form action="http://xxx.com/mailer.cfm" method="post" class="style15">
  5. <table border="0" cellpadding="3" cellspacing="0" class="contact-form">
  6. <tr>
  7.                             <td>NAME:<br />
  8.                             <input name="name" type="text" class="text" value="" size="25" /></td>
  9.                             <td rowspan="4"><div align="right"><a href="javascript:makeClickToTalk('https://xxx.com/','5555555555','clickDemo')" target="_top"><img src="CLICK.gif" alt="Click To Talk" name="clicktotalk" width="200" height="134" border="0"  class="custombutton" id="clicktotalk" style="" /></a></div></td>
  10.         </tr>
  11.                         <tr>
  12.                             <td>COMPANY:<br />
  13.                               <input name="company" type="text" class="text" value="" size="25" /></td>
  14.                   </tr>
  15.                         <tr>
  16.                             <td> BUSINESS:<br />
  17.                               <select name="Business" input type="option" name="name" value="">
  18.                               <option value=""> </option>
  19.                               <option value="ad agency">Ad Agency</option>
  20.                               <option value="auto dealership">Auto Dealership</option>
  21.                               <option value="education">Education</option>
  22.                               <option value="financial">Financial</option>
  23.                               <option value="health/fitness center">Health/Fitness Center</option>
  24.                               <option value="home builders/contractors">Home Builders/Contractors</option>
  25.                               <option value="home improvement">Home Improvement</option>
  26.                               <option value="insurance">Insurance</option>
  27.                               <option value="land developer">Land Developer</option>
  28.                               <option value="legal">Legal</option>
  29.                               <option value="medical">Medical</option>
  30.                               <option value="motorcycle dealer">Motorcycle Dealer</option>
  31.                               <option value="multi-housing industry">Multi-Housing Industry</option>
  32.                               <option value="publisher">Publisher</option>
  33.                               <option value="real estate">Real Estate</option>
  34.                               <option value="retail">Retail</option>
  35.                               <option value="rv dealer">RV Dealer</option>
  36.                               <option value="sports &amp; entertainment">Sports &amp; Entertainment</option>
  37.                               <option value="transportation">Transportation</option>
  38.                               <option value="travel">Travel</option>
  39.                               <option value="watercraft dealer">Watercraft Dealer</option>
  40.                               <option value="other">Other</option>
  41.                               </select></td>    
  42. <td></td>
  43. </tr>
  44.                         <tr>                    
  45.                             <td colspan="2"> E-MAIL:<br />
  46.                               <input name="email" type="text" class="text" value="" size="25" /></td>
  47. <td></td>
  48.                         </tr>
  49.                         <tr>
  50.                           <td colspan="2" align="left">PHONE NUMBER:<br />
  51.                                                 <input name="phone" type="text" class="text" value="" size="3" maxlength="3" />
  52.                                                 <input name="phone2" type="text" class="text" value="" size="3" maxlength="3" />
  53.                                                 <input name="phone3" type="text" class="text" value="" size="4" maxlength="4" />                                                
  54.                                                 </tr>
  55.                         <tr>
  56.                           <td colspan="2" align="left">HOW CAN WE HELP?<br />
  57.                       <textarea name="comments" cols="55" rows="5"></textarea>                      </tr>
  58.                         <tr>
  59.                       <td  colspan="2" align="left"><input type="submit"  class="custombutton" value="" name="send_email" style="background-image:url(submit.jpg); width:75px; height:31px; border:0;"  />                      </tr>
  60.                     </table>            
  61.     </form>
Mar 16 '09 #1

✓ answered by acoder

OK, from line 30-33, you have:
Expand|Select|Wrap|Line Numbers
  1.    <cfif Len(Trim(errorMsg)) GT 0>
  2.         <cfset urlString = URLEncodedFormat(errorMsg)>
  3.         <cfset valueString = "name=#URLEncodedFormat(form.name)#&company=#URLEncodedFormat(form.company)#&email=#URLEncodedFormat(form.email)#&phone=#URLEncodedFormat(form.phone)#&comments=#URLEncodedFormat(form.comments)#">
  4.         <cflocation url="#cgi.HTTP_REFERER#?email_error=1&error_msg=#urlString#&#valueString#">
Change that to:
Expand|Select|Wrap|Line Numbers
  1.    <cfif Len(Trim(errorMsg)) GT 0>
  2.         You have the following errors:<br>
  3.         <cfoutput>#errorMsg#</cfoutput>
  4.         Please correct them.
You could, of course, add some HTML/CSS to improve the display (position, colours, etc.)

14 4320
acoder
16,027 Expert Mod 8TB
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.
Mar 17 '09 #2
@acoder

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
Mar 17 '09 #3
acoder
16,027 Expert Mod 8TB
OK, from line 30-33, you have:
Expand|Select|Wrap|Line Numbers
  1.    <cfif Len(Trim(errorMsg)) GT 0>
  2.         <cfset urlString = URLEncodedFormat(errorMsg)>
  3.         <cfset valueString = "name=#URLEncodedFormat(form.name)#&company=#URLEncodedFormat(form.company)#&email=#URLEncodedFormat(form.email)#&phone=#URLEncodedFormat(form.phone)#&comments=#URLEncodedFormat(form.comments)#">
  4.         <cflocation url="#cgi.HTTP_REFERER#?email_error=1&error_msg=#urlString#&#valueString#">
Change that to:
Expand|Select|Wrap|Line Numbers
  1.    <cfif Len(Trim(errorMsg)) GT 0>
  2.         You have the following errors:<br>
  3.         <cfoutput>#errorMsg#</cfoutput>
  4.         Please correct them.
You could, of course, add some HTML/CSS to improve the display (position, colours, etc.)
Mar 17 '09 #4
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.
Mar 17 '09 #5
I am trying this:

Expand|Select|Wrap|Line Numbers
  1. <cfif Len(Trim(errorMsg)) GT 0> 
  2.         <p style="font:bold 12px Verdana, Arial, Helvetica, sans-serif; color:red;">You have the following errors:<br> 
  3.         <cfoutput>#errorMsg</cfoutput> 
  4.         Please correct them. </p>
Mar 17 '09 #6
acoder
16,027 Expert Mod 8TB
You forgot the closing # sign:
Expand|Select|Wrap|Line Numbers
  1. <cfoutput>#errorMsg#</cfoutput>
Mar 17 '09 #7
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.
Mar 17 '09 #8
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
Mar 17 '09 #9
@confusedfusion

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.
Mar 17 '09 #10
acoder
16,027 Expert Mod 8TB
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.
Mar 17 '09 #11
@acoder
I like your suggestion of Opt2 but not sure how to get that to work.
Mar 17 '09 #12
acoder
16,027 Expert Mod 8TB
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.
Expand|Select|Wrap|Line Numbers
  1. <cfif isdefined("form.send_email")>
  2. <!--- mailer code here --->
  3. </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:
Expand|Select|Wrap|Line Numbers
  1. <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.
Mar 17 '09 #13
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.
Mar 17 '09 #14
acoder
16,027 Expert Mod 8TB
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.
Mar 18 '09 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Phil Powell | last post by:
$sql = 'INSERT INTO fs_usermetadata (' . substr(trim($cols), 0, strrpos(trim($cols), ',')) . ') VALUES (' . substr(trim($values), 0, strrpos(trim($values), ',')) . ')'; if (!mysql_query($sql))...
3
by: Kim Haines | last post by:
I need help finding where an error is occuring in my code. I use a try-catch block like this in my global.asa: try { //my code } catch (e) { Application('errormsg') = ("An exception...
2
by: Alistair | last post by:
hey peoples. I have a simple form (currently two fields) which is then passed to an ASP page thats stores the data in a dbase I have an error checking script which I can't get to work. the...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
7
by: Paul Marshall | last post by:
Hi I am my wits end! I have a PHP script running that captures variables posted from a form on the previous page. The script then emails the results using the mail() function. The script is...
3
by: comp.lang.php | last post by:
I have a counter that evokes the "Three Strikes You're Out" rule.. if you make more than N mistakes it auto-resets to avoid flooding $_SESSION with attempt after attempt, etc. However, the...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
9
Haitashi
by: Haitashi | last post by:
<cfif (Attributes.icq NEQ "") AND IsNumeric (Attributes.icq) AND IsValid("integer", Attributes.icq)> <cfset Variables.oStudentProfile.icq = Attributes.icq /> <cfelse> <cfset temp =...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.