View Full Version : form
emma85
08-29-2002, 11:08 AM
take a look at this page:
http://www.beeweeb.com/download/dlmapper2k.shtml
I like to do one of them validation forms. that is: the webuser first fills in a form with required fields, and if the form is filled with address and ph and such the user gets to download, but if not -> no download!
simple?
I can't figure it out. do I need cgi for this?
or maybe some more computer awareness...
/emma
jalarie
08-29-2002, 03:25 PM
1. You have two form tags. Get rid of one of them.
2. Add the following to the form tag:
onsubmit="return CheckIt();"
3. Create a JavaScript function called CheckIt to verify the required fields. If a field does not verify correctly, do a "return false;" after the check.
ShriekForth
08-29-2002, 04:04 PM
When you are going to be validating serveral fields, it's good to make generic functions to help in the validation. In the case of this form, an email check and a check to see that something other than the default 0 index is selected will work.
function validateEmail(email) {
var re = /^\w+@\w+(\.\w+)+$/; //look for a single uninterupted word followed by a @ then a .
if (email.value == "") {
email.focus()
return false;
}
if (re.test(email.value)) {
return true; //change this to return true or this will never post.
}
email.focus()
return false;
}
function isSelected(item){
if (item.selectedIndex == 0){
item.focus();
return false;
}
else{
return true;
}
}
function validateForm(){
if ((validateEmail(document.DLMapper.email)) && (isSelected(document.DLMapper.country))){
return true;
}
else{
return false;
}
}
jalarie's method of inSubmit works best. I called my function validateForm however. How you want to let the user know why it is not going to post will be up to you. The functions I have there will set focus to the field that does not pass. That will get it posted, if they have a properly formatted email address, and have selected a country. However storing that infomation will need to be done serverside, CGI, PHP, ASP whichever.
ShriekForth
BTW in the example above I did assume that you did give your form the name of "DLMapper"
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.