...

View Full Version : Form Validator



saxchick1
09-06-2011, 12:40 AM
So far, my for validator works, but when I want to see if it works for when a user leaves the message area blank, my form just sends the email anyway. Also, I am not too sure how to go about validating my my captcha code.






<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function ValidateContactForm()
{
var name = document.ContactForm.name;
var email = document.ContactForm.email;
var text = document.ContactForm.text;

if (name.value == "")
{
window.alert("Please enter your name.");
name.focus();
return false;
}

if (email.value == "")
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf("@", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (comment.value == "")
{
window.alert("Please provide a detailed description or comment.");
text.focus();
return false;
}
return true;
}
</script>
</head>
<body>

<div id="templatemo_wrapper">

<div id="templatemo_header">



<ul id="social_box">
<li><a href="http://www.facebook.com/"><img src="images/facebook.png" alt="facebook" /></a></li>
<li><a href="http://www.twitter.com/"><img src="images/twitter.png" alt="twitter" /></a></li>
</ul>

<div id="site_title">
<h1><a href="index.htm"><img src="images/logo2.png" alt="logo" /><span></span></a></h1>
</div> <!-- end of site_title -->


</div> <!-- end of templatemo_header -->

<div id="templatemo_menu">
<div class="home"><a href="index.htm"></a></div>
<ul>
<li><a href="index.htm"><span>Home</span></a></li>
<li><a href="test.htm"><span>Test</span></a></li>
<li><a href="examples.htm"><span>Examples</span></a></li>
<li><a href="Questions.htm"><span>Questions</span></a></li>
<li><a href="contact.htm"><span>Contact</span></a></li>
<li><a href="comments.htm">Have A Comment?<span>Comments</span></a></li>
</ul>
</div>

<!-- end of templatemo_menu -->

<div id="templatemo_content_wrapper">
<div id="templatemo_content_top"></div>
<div id="templatemo_content">

<h2>Contact</h2>



<p><b>E-mail: starr05@gmail.com </b></p>

<p><b><a href="http://www.twitter.com/">Twitter</a></b></p>

<div class="cleaner_h50"></div>

<div id="contact_form">

<h4>Quick Contact</h4>

<form method="post" name="ContactForm" id="contact" action="email.php" onsubmit="return ValidateContactForm();">

<div class="col_w340 float_l">

<label for="name">Name (* Required):</label> <input name="name" type="text" class="input_field" id="author" maxlength="40" />
<div class="cleaner_h10"></div>

<label for="subject">Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" />
<div class="cleaner_h10"></div>


<label for="email">Email (* Required):</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" />
<div class="cleaner_h10"></div>


Type verification image:<br />
<input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"/>
<img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /><br />
<br />

</div>



<div class="col_w340 float_r">

<label for="text">Message (*Required):</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
<div class="cleaner_h10"></div>

<input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />
<input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" />

</div>

</form>

</div>

<div class="cleaner"></div>

</div>
<div id="templatemo_content_bottom"></div>
</div>

<div id="templatemo_sp_box">

<div class="col_w340 float_l">

</div>
</div>

<div class="col_w340 float_r">

</div>
</div>

</div>

<div id="templatemo_footer">


Copyright 2011 <a href="www.twitter.com/">Starr</a><br/>
<a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a>
by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a>

</div> <!-- end of templatemo_footer -->

</div> <!-- end of templatemo_wrapper -->

</body>
</html>








<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>


<?php


$first_name=$_POST['name'];
$email_address=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['text'];

mail("starr05@gmail.com","Vadhir Derbez Photography: $subject",
$message, "From: $first_name <$email_address>");

echo "Thank you for using our mail form.<br/>";
echo "Your email has been sent.";
?>




</body>
</html>







<?php


header('Content-type: image/jpeg');

$width = 50;
$height = 24;

$my_image = imagecreatetruecolor($width, $height);

imagefill($my_image, 0, 0, 0xFFFFFF);

// add noise
for ($c = 0; $c < 40; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
imagesetpixel($my_image, $x, $y, 0x000000);
}

$x = rand(1,10);
$y = rand(1,10);

$rand_string = rand(1000,9999);
imagestring($my_image, 5, $x, $y, $rand_string, 0x000000);

setcookie('tntcon',(md5($rand_string).'a4xn'));

imagejpeg($my_image);
imagedestroy($my_image);
?>

Logic Ali
09-06-2011, 03:41 AM
It would be easy to answer this, but you're asking a question that the error console must be answering.

Always start there.

Arbitrator
09-06-2011, 03:59 AM
but when I want to see if it works for when a user leaves the message area blank, my form just sends the email anyway.comment.value presumably refers to an element with name="comment" which, as far as I can tell, doesn't exist. Perhaps you meant to use something like:


if (document.getElementById("text").value === "") {
window.alert("Please provide a detailed description or comment.");
document.getElementById("text").focus();
return false;
}

(It's bad practice to reference element names as property names, so I used getElementById to reference your elements by their IDs instead.)

Philip M
09-06-2011, 12:03 PM
Form validation of the pattern if (document.getElementById("text").value === "") { is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. Suggest you make it that at least 6 alpha characters are required in a comment field to pass the validation.

The same applies to email addresses - if (email.value.indexOf("@", 0) < 0) is totally inadequate validation.
This subject has been covered a zillion times in this forum.

saxchick1
09-07-2011, 06:51 PM
It would be easy to answer this, but you're asking a question that the error console must be answering.

Always start there.

When I tested it, I didnt get an error in the error console.

Logic Ali
09-07-2011, 07:06 PM
When I tested it, I didnt get an error in the error console.

You assign to comment.value but nowhere is there defined a variable or even an ID with that name. That must (and does) generate an error.

saxchick1
09-07-2011, 08:51 PM
I went back and made some changes to my form and saw a few examples on here on how validate an email address. Now, when I test it, the only error I get is "Expected '(' Line: 17 Char: 1. Before that I had the return statement outside of function, I moved my return statement from where I validated the comment area outside and it worked, but it seems now I have more errors than I expected.




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function ValidateContactForm()
{
if (document.getElementById("author").value === "")
{
window.alert("Please provide a detailed description or comment.");
document.getElementById("author").focus();
}
if
{
((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(document.form2.

email.value)) {
alert ("Invalid email address! Please retry.");
document.ContactForm.email.value == ""; // clear the field
document.ContactForm.email.focus(); // and refocus on it
return false;
}
if (document.getElementById("text").value === "")
{
window.alert("Please provide a detailed description or comment.");
document.getElementById("text").focus();
}
return false;
}
}
</script>
</head>
<body>

<div id="templatemo_wrapper">

<div id="templatemo_header">



<ul id="social_box">
<li><a href="http://www.facebook.com/"><img

src="images/facebook.png" alt="facebook" /></a></li>
<li><a href="http://www.twitter.com/"><img src="images/twitter.png"

alt="twitter" /></a></li>
</ul>

<div id="site_title">
<h1><a href="index.htm"><img src="images/logo2.png" alt="logo"

/><span></span></a></h1>
</div> <!-- end of site_title -->


</div> <!-- end of templatemo_header -->



<!-- end of templatemo_menu -->

<div id="templatemo_content_wrapper">
<div id="templatemo_content_top"></div>
<div id="templatemo_content">

<h2>Contact</h2>



<p><b>E-mail: starr05@gmail.com </b></p>

<p><b><a href="http://www.twitter.com/">Twitter</a></b></p>

<div class="cleaner_h50"></div>

<div id="contact_form">

<h4>Quick Contact</h4>

<form method="post" name="ContactForm" id="contact" action="email.php"

onsubmit="return ValidateContactForm();">

<div class="col_w340 float_l">

<label for="author">Name (* Required):</label> <input

name="author" type="text" class="input_field" id="author" maxlength="40" />
<div class="cleaner_h10"></div>

<label for="subject">Subject:</label> <input name="subject" type="text" class="input_field"

id="subject" maxlength="40" />
<div class="cleaner_h10"></div>


<label for="email">Email (* Required):</label> <input

name="email" type="text" class="input_field" id="email" maxlength="40" />
<div class="cleaner_h10"></div>


Type verification image:<br />
<input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid

#CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif;

font-size:11px;"/>
<img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it

in the box" width="50" height="24" align="absbottom" /><br />
<br />

</div>



<div class="col_w340 float_r">

<label for="text">Message (*Required):</label> <textarea

id="text" name="text" rows="0" cols="0" class="required"></textarea>
<div class="cleaner_h10"></div>

<input type="submit" class="submit_btn float_l" name="submit"

id="submit" value="Send" />
<input type="reset" class="submit_btn float_r" name="reset"

id="reset" value="Reset" />

</div>

</form>

</div>

<div class="cleaner"></div>

</div>
<div id="templatemo_content_bottom"></div>
</div>

<div id="templatemo_sp_box">

<div class="col_w340 float_l">

</div>
</div>

<div class="col_w340 float_r">

</div>
</div>

</div>

<div id="templatemo_footer">


Copyright 2011 <a href="www.twitter.com/">Starr</a><br/>
<a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a>
by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a>

</div> <!-- end of templatemo_footer -->

</div> <!-- end of templatemo_wrapper -->

</body>
</html>

saxchick1
09-08-2011, 03:10 AM
I think I am on the right track now. My error console says (Expected ')' Line:28 Char:52), did I leave a ) out? Also, when I test it, the alert box shows up, but when I click ok, the message gets sent to the email address. Not too sure what I did and I am also not too sure if I validated the email address right.




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function ValidateContactForm()
{
if (document.getElementById("text").value === "")
{
window.alert("Please provide a detailed description or comment.");
document.getElementById("text").focus();
}
if (document.getElementById("author").value === "")
{
window.alert("Please provide your name.");
document.getElementById("author").focus();
}
if (document.getElementById("verif_box").value === "")
{
window.alert("Please enter captcha code.");
document.getElementById("verif_box").focus();
}

if

(!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(emailAddress.val

ue))) {
window.alert("Please enter a valid email address.");
document.getElementById("email").focus();
}
return false;
}

</script>
</head>
<body>

<div id="templatemo_wrapper">

<div id="templatemo_header">



<ul id="social_box">
<li><a href="http://www.facebook.com/"><img

src="images/facebook.png" alt="facebook" /></a></li>
<li><a href="http://www.twitter.com/"><img src="images/twitter.png"

alt="twitter" /></a></li>
</ul>

<div id="site_title">
<h1><a href="index.htm"><img src="images/logo2.png" alt="logo"

/><span></span></a></h1>
</div> <!-- end of site_title -->


</div> <!-- end of templatemo_header -->



<!-- end of templatemo_menu -->

<div id="templatemo_content_wrapper">
<div id="templatemo_content_top"></div>
<div id="templatemo_content">

<h2>Contact</h2>



<p><b>E-mail: starr05@gmail.com </b></p>

<p><b><a href="http://www.twitter.com/">Twitter</a></b></p>

<div class="cleaner_h50"></div>

<div id="contact_form">

<h4>Quick Contact</h4>

<form method="post" name="ContactForm" id="contact" action="email.php"

onsubmit="return ValidateContactForm();">

<div class="col_w340 float_l">

<label for="author">Name (* Required):</label> <input

name="author" type="text" class="input_field" id="author" maxlength="40" />
<div class="cleaner_h10"></div>

<label for="subject">Subject:</label> <input name="subject" type="text" class="input_field"

id="subject" maxlength="40" />
<div class="cleaner_h10"></div>


<label for="email">Email (* Required):</label> <input

name="email" type="text" class="input_field" id="email" maxlength="40" />
<div class="cleaner_h10"></div>


Type verification image:<br />
<input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid

#CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif;

font-size:11px;"/>
<img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it

in the box" width="50" height="24" align="absbottom" /><br />
<br />

</div>



<div class="col_w340 float_r">

<label for="text">Message (*Required):</label> <textarea

id="text" name="text" rows="0" cols="0" class="required"></textarea>
<div class="cleaner_h10"></div>

<input type="submit" class="submit_btn float_l" name="submit"

id="submit" value="Send" />
<input type="reset" class="submit_btn float_r" name="reset"

id="reset" value="Reset" />

</div>

</form>

</div>

<div class="cleaner"></div>

</div>
<div id="templatemo_content_bottom"></div>
</div>

<div id="templatemo_sp_box">

<div class="col_w340 float_l">

</div>
</div>

<div class="col_w340 float_r">

</div>
</div>

</div>

<div id="templatemo_footer">


Copyright 2011 <a href="www.twitter.com/">Starr</a><br/>
<a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a>
by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a>

</div> <!-- end of templatemo_footer -->

</div> <!-- end of templatemo_wrapper -->

</body>
</html>

Arbitrator
09-08-2011, 06:21 AM
My error console says (Expected ')' Line:28 Char:52), did I leave a ) out?I can't test your document directly as an XHTML document because your source code has PHP code in it that causes it to not be well-formed XML.

In the provided code, line 28 only has one to two characters (line-breaking characters), so I'm not sure what that error message means.

I suspect that the error is within these three lines of code (lines 31 through 33):


(!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(emailAddress.val

ue))) {

Note that, in the above code, an if statement's condition is broken over three lines. The first break comes in the middle of a property name (i.e., value).

saxchick1
09-08-2011, 09:00 PM
I can't test your document directly as an XHTML document because your source code has PHP code in it that causes it to not be well-formed XML.

In the provided code, line 28 only has one to two characters (line-breaking characters), so I'm not sure what that error message means.

I suspect that the error is within these three lines of code (lines 31 through 33):


(!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(emailAddress.val

ue))) {

Note that, in the above code, an if statement's condition is broken over three lines. The first break comes in the middle of a property name (i.e., value).

I went back and changed things in my script, but still getting errors (Expected ')' Line:13 Char:125)

} else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a- - This is line 13.

Also, I think I may have two different ways of calling the 'name' textbox, in my php I have it as name, and in my form I have it as 'author'




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function ValidateContactForm() {
if (document.getElementById("author").value === "") {
window.alert("Please provide a detailed description or comment.");
document.getElementById("author").focus();
} else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(document.ContactForm.email.value)) {
alert ("Invalid email address! Please retry.");
document.ContactForm.email.value == ""; // clear the field
document.ContactForm.email.focus(); // and refocus on it
} else if (document.getElementById("text").value === "") {
window.alert("Please provide a detailed description or comment.");
document.getElementById("text").focus();
} else {
return true; // successful
}
return false; // failed validation
}

</script>
</head>
<body>

<div id="templatemo_wrapper">

<div id="templatemo_header">



<ul id="social_box">
<li><a href="http://www.facebook.com/"><img src="images/facebook.png" alt="facebook" /></a></li>
<li><a href="http://www.twitter.com/"><img src="images/twitter.png" alt="twitter" /></a></li>
</ul>

<div id="site_title">
<h1><a href="index.htm"><img src="images/logo2.png" alt="logo" /><span></span></a></h1>
</div> <!-- end of site_title -->


</div> <!-- end of templatemo_header -->

<span>Comments</span></a></li>
</ul>
</div>

<!-- end of templatemo_menu -->

<div id="templatemo_content_wrapper">
<div id="templatemo_content_top"></div>
<div id="templatemo_content">

<h2>Contact</h2>



<p><b>E-mail: starr05@gmail.com </b></p>

<p><b><a href="http://www.twitter.com/">Twitter</a></b></p>

<div class="cleaner_h50"></div>

<div id="contact_form">

<h4>Quick Contact</h4>

<form method="post" name="ContactForm" id="contact" action="email.php" onsubmit="return ValidateContactForm();">

<div class="col_w340 float_l">

<label for="author">Name (* Required):</label> <input name="author" type="text" class="input_field" id="author" maxlength="40" />
<div class="cleaner_h10"></div>

<label for="subject">Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" />
<div class="cleaner_h10"></div>


<label for="email">Email (* Required):</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" />
<div class="cleaner_h10"></div>


Type verification image:<br />
<input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"/>
<img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /><br />
<br />

</div>



<div class="col_w340 float_r">

<label for="text">Message (*Required):</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
<div class="cleaner_h10"></div>

<input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />
<input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" />

</div>

</form>

</div>

<div class="cleaner"></div>

</div>
<div id="templatemo_content_bottom"></div>
</div>

<div id="templatemo_sp_box">

<div class="col_w340 float_l">

</div>
</div>

<div class="col_w340 float_r">

</div>
</div>

</div>

<div id="templatemo_footer">


Copyright 2011 <a href="www.twitter.com/">Starr</a><br/>
<a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a>
by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a>

</div> <!-- end of templatemo_footer -->

</div> <!-- end of templatemo_wrapper -->

</body>
</html>





[PHP]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>


<?php


$first_name=$_POST['name'];
$email_address=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['text'];

mail("starr05@gmail.com","Subject: $subject",
$message, "From: $first_name <$email_address>");

echo "Thank you for using our mail form.<br/>";
echo "Your email has been sent.";
?>




</body>
</html>

[PHP]

Logic Ali
09-08-2011, 10:15 PM
I went back and changed things in my script, but still getting errors (Expected ')' Line:13 Char:125)

} else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a- - This is line 13.It means the parentheses are unbalanced. Just balance them.

saxchick1
09-09-2011, 01:41 AM
I went back and changed things in my script, but still getting errors (Expected ')' Line:13 Char:125)

} else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a- - This is line 13.It means the parentheses are unbalanced. Just balance them.

I just added a parentheses and still picks up the same error.

Logic Ali
09-09-2011, 02:27 AM
I just added a parentheses and still picks up the same error.
This line has balanced parentheses, although it still has more than it needs.
The regex is still wrong but you can work on that.

if( !(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(document.ContactForm.email.value ) ) )

saxchick1
09-09-2011, 02:39 AM
What is regex? This is my first time having to validate an email address, so I am not too sure of things.

Arbitrator
09-09-2011, 06:23 AM
I went back and changed things in my script, but still getting errors (Expected ')' Line:13 Char:125)

} else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a- - This is line 13.



function ValidateContactForm() {
if (document.getElementById("author").value === "") {
window.alert("Please provide a detailed description or comment.");
document.getElementById("author").focus();
} else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(document.ContactForm.email.value)) {
alert ("Invalid email address! Please retry.");
document.ContactForm.email.value == ""; // clear the field
document.ContactForm.email.focus(); // and refocus on it
} else if (document.getElementById("text").value === "") {
window.alert("Please provide a detailed description or comment.");
document.getElementById("text").focus();
} else {
return true; // successful
}
return false; // failed validation
}A review of this code indicates that you're missing two RIGHT PARENTHESIS characters immediately before the RIGHT CURLY BRACKET character at the end of the line containing the regular expression.

Another way of looking at it is that you have two too many LEFT PARENTHESES characters at the start of your if statement's condition (on the line containing the regular expression). One of these is immediately before the EXCLAMATION MARK character and the other is immediately after it.

Additionally, you have this problematic code: document.ContactForm.email.value == ""; // clear the field. Because you used the equality operator (i.e., ==) instead of the assignment operator (i.e., =), this line will simply return true or false and otherwise have no effect.

(And, as I've already mentioned, you should be using IDs to reference your elements, so document.ContactForm.email.value should be document.getElementById("email").value.


Also, I think I may have two different ways of calling the 'name' textbox, in my php I have it as name, and in my form I have it as 'author'This is not a PHP problem. Next time, please submit processed HTML or XHTML code that does not include any PHP code that can be copied and pasted into a text editor so that people can test your code without jumping through hoops.

Currently, to test your code, one has to (A) render it as HTML with errors due to PHP code; (B) render it as XHTML/XML with fatal errors due to PHP code (that will prevent the entire document from displaying assuming that it displays at all); (C) look through your code and fix all of the errors that have nothing to do with your primary problem before testing for your problem; or (D) pick out parts of your document and transplant them to a new, properly written document to test them. (I ended up going with D.)

saxchick1
09-10-2011, 02:28 AM
A review of this code indicates that you're missing two RIGHT PARENTHESIS characters immediately before the RIGHT CURLY BRACKET character at the end of the line containing the regular expression.

Another way of looking at it is that you have two too many LEFT PARENTHESES characters at the start of your if statement's condition (on the line containing the regular expression). One of these is immediately before the EXCLAMATION MARK character and the other is immediately after it.

Additionally, you have this problematic code: document.ContactForm.email.value == ""; // clear the field. Because you used the equality operator (i.e., ==) instead of the assignment operator (i.e., =), this line will simply return true or false and otherwise have no effect.

(And, as I've already mentioned, you should be using IDs to reference your elements, so document.ContactForm.email.value should be document.getElementById("email").value.

This is not a PHP problem. Next time, please submit processed HTML or XHTML code that does not include any PHP code that can be copied and pasted into a text editor so that people can test your code without jumping through hoops.

Currently, to test your code, one has to (A) render it as HTML with errors due to PHP code; (B) render it as XHTML/XML with fatal errors due to PHP code (that will prevent the entire document from displaying assuming that it displays at all); (C) look through your code and fix all of the errors that have nothing to do with your primary problem before testing for your problem; or (D) pick out parts of your document and transplant them to a new, properly written document to test them. (I ended up going with D.)

I think I am just going to start off from scratch. I read different examples and had several people help me, that I am very confused now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum