I am trying to set up a way for visitors of my website to email me through a web-based form. In this form I am asking for: 1) First Name 2) Last Name 3) Email address 4) Confirm the email address (type it again) 5) The comments I have a few problems I need help with. First of all, how do I have the form say there is an "error" if the email addresses do not match? Second of all, how do I set it up so that it tells the user what they did wrong? (i.e.: Didn't enter first name, email addresses don't match, etc.) In case you care to see the site: www.riggottphoto.com/contact Thank you in advance for any help!
You can use Javascript for client side to verify this information. Besides client side validation, I would strongly recommend server side validation as well. Do you know what language support is on your server?
Yes for the error reporting functionality you should use JavaScript since the execution will be on the client-side(on each client/browser). This takes unnecessary burden off the server and is faster. Here is a simple example of a HTML form controlled by a JavaScript that uses Regular Expressions(RegExp): HTML Form controlled by JavaScript Here is some explainations on RegExp and how to achieve this functionality: (The script can be downloaded at the bottom of the page) How to use RegExp in JavaScript For the core functionality of sending the email you should use what ever server-side scripting language your server features. Here is an example that uses servlets(Java) as server-side scripting language and could be combined with JavaScript error reporting script presented above: Email Form that uses a Servlet to send emails Note:Since I haven't hard coded the recipient adress I have blocked access with a password. It would surely be used in a spammy manner otherwise However, if you wan't to use this Servlet you could easily change the code for the recipient adress to your email address. The code is downloadable at the bottom of this page: Servlet that sends emails Combine the error reporting JavaScript(but modify the script to fit the fields in the form) with whatever server-side script you like. Although Servlets and Jsp are the fastest server-side scripting language it can be somewhat hard to use since you need to know at least basic Java programming. There are alot of other more simpler server-side scripting languages like PHP or ASP. Anyway, it doesn't matter much what technique you use if you don't plan modify the code. Hope you find this info useful. Good luck.
This looks great. I am going to try to impliment some of this over the weekend. I appreciate the detailed assistance. I'm not able to answer the question regarding what my server supports. I use esosoft.com to host the site. I don't know if that helps. I will post again later after I have given some of this a whirl! Again, I appreciate it. Regards.
When doing a site search with Google on esosoft.com(site:esosoft.com servlet) for the word "servlets" it didn't come up anything. Same search with "PHP" came up with a few pages. I would either ask them to start using a servlet engine like Tomcat or you could just turn to PHP. There are alot of free PHP scripts availible. However, I only have free Servlet script so I can't give you one. The JavaScript I linked to in previous post could still be useful if the PHP script you find doesn't already feature one. Good luck
I really appreciate your help. Would you mind taking a look at what I have done and helping out a little? My JavaScript isn't as great as it could be. Attached is the html form that I tried to put together. Also, attached is the js file that I modified. Again, my ultimate goal is to have notification pop up if the two email address fields don't match. In the attached js file I simply am messing around to see if I can even get the form to work with the js. Any help would be appreciated. Thank you! (Note that the js file has been converted to txt for uploading purposes.)
Since your HTML form's functionality isn't the same as the JavaScript example I provided you should do some changes. You don't need to look for a correct email syntax in both adresses, i.e address field and confirmation field. If you are trying to make sure a correct syntax is used according to the pattern you have chosen, simply check the email adress, and them look if it equals your confirmation address. If they are the same you know that the confirmation address also have a correct syntax. By correct syntax I mean having a @ sign and/or ending with a specific domain name etc...or whatever you wan't to make sure the user have filled in. First look for correct syntax by using regexp... then something like this: /*To see if the two adress fields match*/ if (a.toUpperCase() != s.toUpperCase()) { window.alert("The confirmation address doesn't match, please try again."); } Code (markup): When everything works, and when you tested the script on diffrent browsers, you can add some fancy things like removing text from the fields that are incorrect from the form, and leave those fields that were correct. Also, since I am a Java programmer there are probably some code that could be done better in a more JavaScript-like manner. --- JavaScript is the fastest way to do this because no data need to be sent to the server for error control and the server doesn't need to perform any extra processing. But you could - maybe to be sure clients/browsers that don't allow active scripting also will be error checked - do the error checking on the server-side with servlets, cgi, php or whatever server-side language you like. Good Luck
The problem is that when I run the script that I sent you, it doesn't pop up an error message when I do it incorrectly. There is no message when I do it incorrectly. I simply fill out the form however I want and no message pops up. So before I get to matching the form fields, I need to make sure the script is working. Any thoughts?
window.alert("I wonder if this script being called?"); somewhere at the beginning of the .js file. Be sure you have linked it correctly from your HTML file.