If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > asp/html comments form

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-26-06, 10:39
jonbenitos jonbenitos is offline
Registered User
 
Join Date: Jul 2006
Posts: 1
asp/html comments form

Hi everyone,
I would be really grateful if someone could help me here, I've recently put a comments form on my website but i've been trying to find out how to add validation to the input boxes and its giving me a headache as i'm not very good with asp. My form is located at http://www.galaxywindows.co.uk/contact/form.html

but when the submit button is pressed even if no data is entered it still says message sent and I recieve it in my inbox. could someone help me with fixing this as I'm not really sure how.

Many thanks
Reply With Quote
  #2 (permalink)  
Old 07-26-06, 12:16
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
__________________
Paul
Reply With Quote
  #3 (permalink)  
Old 08-01-06, 10:43
igordonin igordonin is offline
Registered User
 
Join Date: Jul 2006
Posts: 56
Validating data in ASP or with JavaScript

There are two ways you can validate data from a ASP based form. Either you can use the next page to identify the error and then send the user back to the form page where you should let the user know which field he got it wrong, OR you can use JavaScript to valida your form on submittion.

Here, lemme give you an example based on your simple form:

Code:
function validateForm(form) {
	this.form = form;
	errors = 0
	

/* ------------------------------------------
form contact
------------------------------------------ */

if (form == "contact") {

form = document.contact;

/* email*/

if (errors== 0) {

Ctrl = form.email;

if ((Ctrl.value == "" || Ctrl.value.indexOf('@', 0) == -1) || Ctrl.value.indexOf('.') == -1) {

validatePrompt(Ctrl, "Please, type in a valid e-mail adress.");
errors++;
}
}


/* name */

if (errors == 0) {

Ctrl = form.name;

if (Ctrl.value == "") {

validatePrompt(Ctrl, "Please, type in your name.");
errors++;

}
}


/* comments */

if (errors == 0) {

Ctrl = form.comments;

if (Ctrl.value == "") {

validatePrompt(Ctrl, "Please, type in your comments.");
errors++;

}
}


/* ------------------------------------------
true or false
------------------------------------------ */

if (errors > 0) {
return false;
} else return true

}


/* ------------------------------------------
Focus and Error Alert
------------------------------------------ */
 function validatePrompt(Ctrl, PromptStr) {
	alert (PromptStr);
	
	if (Ctrl == "NO") {
		return;
	} else {
		Ctrl.focus();
		return;
		}
 }

// -->
Name your form "contact", and make sure you name your fields correctly too.

Also, notice that you may use "NO" instead of Ctrl in the ValidatePrompt Function if you don't want this script to focus on a certain field (like, you wouldn't want to do that if the field were a radio...)

Your form tag should look like this:
Code:
<form name="contact" action="next_asp_file.asp" method="post" target="if any" onSubmit="return validateForm(this.name);" >
Lemme know if this helped.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On