JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 12th, 2012, 07:45 PM
kerryf88 kerryf88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 8 kerryf88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 15 sec
Reputation Power: 0
Refresh page if user entered the wrong validation

So I have this form.html file with JavaScript validation that will validate if the email that user entered is valid or not, if it is, it will be processed by a php file to enter this email to a MySQL database

Here's the javascrip code:
Code:
<script type='text/javascript'>
function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

if(inputText.value.match(mailformat))
{
document.form1.email.focus();
return true;
}
else
{
alert("invalid email");
document.form1.email.focus();
return false;
}
}
<script>


And here is the form tag in my HTML page
Code:
<form name="form1" action="email.php" method="POST">
<input name="email" type='text' id='email'>
<input type="submit" value="Submit" onclick="ValidateEmail(document.form1.email)"/>
</form>


However, when I entered an invalid email, the error message displays but then it also saves the invalid email into my MySQL database, is there a way to only save the validate email address into the database. So when user enters invalid email, the error message will come up and then will refresh the textbox to allow user to enter again

Reply With Quote
  #2  
Old September 13th, 2012, 02:36 AM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,872 Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 16 h 37 m 29 sec
Reputation Power: 2569
Client-side validation should never be used as a replacement for hardened server-side validation. You should be employing checks on the server-side, where a user cannot bypass or alter your validation rules.

Your Javascript event call is not waiting for the function to return a confirmation before submitting the document, this is because it has not been asked to. Also, you should not be running the check when the button is clicked but when the form is submitted.
HTML4Strict Code:
Original - HTML4Strict Code
  1. <form name="form1" action="email.php" method="post" onsubmit="return ValidateEmail(document.form1.email);">
  2.     <input name="email" type='text' id='email'>
  3.     <input type="submit" value="Submit">
  4. </form>
__________________
[PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

W3Fools - A W3Schools Intervention.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Refresh page if user entered the wrong validation

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap