Reply
Validating a form
Old 03-21-2008, 04:30 PM Validating a form
Extreme Talker

Posts: 162
I am trying to use my limited JS skills to work on validating the form on the same page rather than having to reload like in PHP.
I wanted to have it validate on click and then perform the normal action of going to index.php but it looks like its bypassing the validation and just going to the new page. This is a problem because if the person doesnt fill out enough info it wont send the email to my account properly.

Here is what I have any ideas?:
HTML Code:
<form name="contactform" action="index.php" method="post">
Name <br /><input type="text" name="name" style="width:75%"><br />
Email (required if you want a response) <br /><input type="text" name="email" style="width:75%">  <br />
Subject <br /><input type="text" name="subject" style="width:75%"><br />
Message <br />
<textarea rows="15" cols="65" name="message"></textarea><br />
Validation<select name="notspam"><br />
		<option value="invalid" selected="selected">Don't accept me I am a spam bot.</option>
		<option value="valid">I am a human believe me!</option>
	</select><br />
<input type="submit" name="send" value="Send!" onSubmit="return validate()">
</form> 
EDIT: On a side note, you think having a dropdown box like that is good enough to stop spam?
__________________
DVD Movie Release Database: http://www.couchpotatoesonline.com
Truly is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 03-21-2008, 05:48 PM Re: Validating a form
vangogh's Avatar
Post Impressionist

Posts: 8,420
Name: Steven Bradley
Location: Boulder, Colorado
One very important thing to keep in mind with form validation using JavaScript is that you still need to validate on the server with something like php. Any validation you do with JavaScript should only be seen as making things easier for the person filling out the form, but there will be absolutely no security or true validation since the JavaScript can easily be circumvented.

If I filled out your form with JavaScript turned off there would be no validation. I could also copy your page, rewrite the JavaScript on my end and still submit the form. Regardless of whether or not you use JavaScript validation you still need to validate on the server.

It won't stop spam since spam is going to be robotic and will ignore the JavaScript.

As far as the details of JavaScript validation there's plenty of info as to how it's done and you'll probably find a lot of different ways how it's done. Search for "form validation javascript" or similar and you should find a lot of tutorials.

The basic idea is usually to check first to see if required fields have been filled out and then check to see if the value entered makes sense. For example an email address is going to take a certain form and you can check to see if the @ symbol is present. Obviously an @ symbol alone doesn't make something an email. How many things you check for depends on how much you want to validate.
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Validating a form
 

Thread Tools

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12153 seconds with 13 queries