Click to See Complete Forum and Search --> : [RESOLVED] ASP Form
drumbum360
01-30-2009, 08:20 PM
I have a form in which the user puts in some info including their email address. The form includes two radio buttons in which the user must select one of the two options. Then, depending on their selection, when they hit submit, it should email them an email.
How can I make the radio buttons mandatory to select prior to pressing submit as well as send an custom message depending on their selection? And, How can I make a (confirmation) checkbox mandatory in the form as well?
Thanks for your help.
buntine
01-30-2009, 08:31 PM
If you want this functionality from the front-end ("prior to pressing submit"), you should look into doing it with JavaScript.
Ideally, for sensitive data, you want validation on both the front-end and the back-end.
Cheers.
downtime
01-31-2009, 11:30 AM
With the Radial button, good form says to have one of the options preselected. If you really want them to choose between two different options, you're going to want to use a drop down box with the first option being a generic "Select your choice" type. You can then make the generic option have a value that you'll check for in your script. If they leave the generic option, then you give them an error message.
As far as making a decision once they've choosen an option, since you'll now have three different possibilities (no choice, choice 1 or choice 2) I would pass that form fields value to a variable, then use Select Case formVariable and create cases for each possible entry.
You can certainly use some Javascript on the form submit to make sure that the fields have been properly filled in, but Javascript can be disabled, so as was recommended you're going to want to also validate the form data while processing it on the server side.
drumbum360
01-31-2009, 03:39 PM
Thanks to both of you for your help. I understand now that I need to validate on the front end with javascript and on the backend with something but I'm not sure what. I am on a time constraint as I need this finished by Monday morning so I think I might only get the front end validation which should be fine in my case.
I know no javascript unfortunately and have been directed to this link: http://www.yourhtmlsource.com/javascript/formvalidation.html
I do plan to use a drop down menu instead of the radio buttons but I'm still unsure how to use the info in this link above to do what I want to do. Is there anything else you can provide me to help this process?
downtime
02-03-2009, 07:45 PM
If you have any security or quality control concerns what so ever (basically, unless you're using this on a closed system like an internal network that restricts access to your web application) you should do server side validation. If javascript is disabled either intentionally or manually, you can't require or validate data that will be processed on the server.
That being said, you can validate on the server and create an error message if one of your conditions aren't met. If you're submitting to a form processing page that then goes to a confirmation page, you can just append an error code to a response.redirect that brings them back to your form page and read the error message on the form page.
Form.asp > submits to email.asp which either redirects back to form.asp?code=1 or thankyou.asp depending on whether an error was found. You assign code a value based on what type of validation failure there was. In your case, there should only be a couple.