-
[RESOLVED] form email validation question
this is my first post, so i'm not sure if something like this has been answered before, so sorry if this is a repost.
what i'm trying to do is have a div become visible on an invalid form entry.
here is the code that i have:
Code:
function validate(c_form,email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[c_form].elements[email].value;
if(reg.test(address) == false) {
function ShowPopup(hoveritem) {
hp2 = document.getElementById("hoverpopup2");
if (hp2.style.display!= "block") {
// Set popup to visible
hp2.style.display = "block";
}
}
return false;
}
return valid;
}
and here is the div:
<div id="hoverpopup2"><div id="message"><?php echo $message ?></div></div>
any ideas of why this isn't working?
-
Try it like this:
Code:
function validate(c_form,email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[c_form].elements[email].value;
var hp2 = document.getElementById("hoverpopup2");
if(reg.test(address) == false) {
hp2.style.display = "block";
return false;
}
hp2.style.display = "none";
return true;
}
At least 98% of internet users' DNA is identical to that of chimpanzees
-
thanks, man; worked perfectly.
-
another question - how would i get a div to display if the form was valid and sent?
-
By having the server program reload the document with a div displayed
At least 98% of internet users' DNA is identical to that of chimpanzees
-
so can you tell me if i'm doing this correctly at all. i'll show you some of the code, and if you need more, let me know.
This is what i have inside the php for when the form goes through:
PHP Code:
unset($_POST);
echo "<script type=\"text/javascript\">\n";
echo "var hp5 = document.getElementById(\"hoverpopup3\");\n";
echo "hp5.style.display = \"block\"; }\n";
echo "</script>";
it doesn't seem to be working, though, so any help would be nice.
thanks.
-
Wait for the document to load
PHP Code:
echo <<<HDOC <script type="text/javascript"> window.onload=function() { var hp5 = document.getElementById("hoverpopup3"); hp5.style.display = "block"; }; </script> HDOC;
At least 98% of internet users' DNA is identical to that of chimpanzees
-
it doesn't seem to be working, i get a parse error stating:
Parse error: syntax error, unexpected $end in process-form.php on line 51.
here is the php file that i'm using, maybe that will help.
PHP Code:
<?php
function is_valid_email($e) {
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $e)) {
return true;
}
else {
return false;
}
}
import_request_variables('pg');
$message = 'Please fix the following error(s): ';
$valid = true;
if (!is_valid_email($email)) {
$valid = false;
$message .= "enter a valid email address, ";
}
if ( empty($full_name) ) {
$valid = false;
$message .= 'name is required, ';
}
if ( $valid ) {
$fh = fopen('new_guests.txt','a+');
$comments2 = str_replace("\r\n",'<br />',$comments);
$content = "$full_name\t";
$content .= "$email\t";
$content .= "$comments2\n";
fwrite($fh,$content);
$subject = str_replace("\r\n",'',$subject);
$email = str_replace("\r\n",'',$email);
$body = "Name: $full_name\n";
$body .= "$full_name says: $comments\n";
$body .= "\n\nIP Address: " . $_SERVER['REMOTE_ADDR'];
mail("?@???","To my mans: $comments",$body,"From: $email\r\n");
// clear the post
unset($_POST);
echo <<<HDOC
<script type="text/javascript">
window.onload=function() {
var hp5 = document.getElementById("hoverpopup3");
hp5.style.display = "block";
};
</script>
HDOC;
}
else {
$message = substr($message, 0, -2) . '.';
}
?>
-
The closing identifier must begin in the first column of the line.
http://www.php.net/manual/en/languag...syntax.heredoc
At least 98% of internet users' DNA is identical to that of chimpanzees
-
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
|
Bookmarks