Probably just a typo -
The one at the top (with an underscore) has the correct id:
Code:
javascript:hide_popup('my_popup')
The one at the bottom (with a dash) does not:
Code:
javascript:hide_popup('my-popup')
Anyways, give this version (probably still needs tweaking) a try:
Code:
<?php
// start the session
session_start();
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
ERROR_REPORTING(E_ALL);
//define variables and receiving email
$name=""; $email=""; $phone=""; $message="";
//for now assume the form has yet to be submitted and so of course has not yet been approved
$submitted = false;
$mailApproved = false;
//validate form inputs
function check_posts() {
$found = array();
foreach ($_POST as $x => $y) {
if ($x == "check") break;
$conditions = array(
"name" => (strlen($y) < 5),
"phone" => (strlen($y) < 6),
"email" => (!filter_var($y, FILTER_VALIDATE_EMAIL)),
"message" => (strlen($y) < 10));
$errors = array(
"name" => "Valid Name ",
"phone" => "Valid phone only",
"email" => "Valid email only",
"message" => "Valid message only" );
if ($conditions[$x]) $found[] = $errors[$x];
}
echo "<div id='checkPostsMsg'>";
$i = 1; if (count($found) > 0) {
echo "<h2 class='invalidheading'>Please address:</h2>";
foreach ($found as $z) { echo "<p class='invalidmessage'>$i. $z</p>"; $i++; }
echo "</div>";
return false;
} else {
echo " Your message has been sent. ";
echo "</div>";
return true;
}
}
//end validation 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" />
<meta name="robots" content="noindex, nofollow"/>
<title>| :: New - PopUP - Form :: | </title>
<style type="text/css">
body {
margin:auto;
padding:0px;
font-family:Arial, Helvetica, sans-serif;
font-size: 12px;
color:#ffffff;
background-color:#ffffff;
}
#wrapper{
background-color:transparent;
border:solid 0px #000000;
margin:auto;
padding:1px;
width:100%;
height:100%;
}
#contact_form_wrap {
background-color:#101a25;
border:2px solid red;
margin:0 auto;
margin-top:30px;
margin-bottom:30px;
padding:10px;
width:340px;
}
#form_title
{
float:left;
width:180px;
color:#fff;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12pt;
font-weight:bold;
}
/*style the sent response*/
h2{
color:#af1010;
text-shadow:#000000 1px 1px 1px;
padding:5px 0 0 3px;
background-color:yellow;
}
label {
font-size: 12px;
font-weight:bold;
}
/*style the fields required*/
.required {
color: red;
font-size: 9px;
float:right;
}
/*style the input fields on hover*/
input:hover{
background-color: #900;
border: 1px solid blue;
}
textarea:hover{
background-color: #900;
border: 1px solid blue;
}
/*style the input fields on focus*/
input:focus {
background-color: #900;
border: 1px solid blue;
}
textarea:focus{
background-color: #900;
border: 1px solid blue;
}
.textfield {
padding:5px 0 0 3px;
width:330px;
height:20px;
border: 1px solid #e9e9e9;
background-color:#303942;
color:#fff;
}
.textarea {
padding:3px;
width:330px;
height:144px;
border: 1px solid #e9e9e9;
background-color:#303942;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
color:#fff;
}
.button, .dbutton {
padding:3px 0 5px 0;
width:175px;
height:25px;
border: none;
background-color:#303942;
font-weight:bold;
cursor:pointer;
color: #f1f1f1;
font-family:Arial, Helvetica, sans-serif;
}
.dbutton {
cursor: text;
cursor: not-allowed;
}
.button:hover {
background-color:#f1f1f1;
color: #333;
}
.dbutton:hover {
background-color:#303942;
border: none;
color: #f1f1f1;
}
.X /*Close(X) to hide form popup*/
{
float:right;
font-size:16px;
font-weight:bold;
color:#fff;
}
p.clear
{
clear:both;
height:0;
padding:0;
margin:0;
}
</style>
<script type='text/javascript'>
var cook = {
set: function(n, v, d){ // cook.set takes (name, value, optional_persist_days) - defaults to session if no days specified
if(d){var dt = new Date();
dt.setDate(dt.getDate() + d);
d = '; expires=' + dt.toGMTString();}
document.cookie = n + '=' + escape(v) + (d || '') + '; path=/';
},
get: function(n){ // cook.get takes (name)
var c = document.cookie.match('(^|;)\x20*' + n + '=([^;]*)');
return c? unescape(c[2]) : null;
}
};
function show_popup(id) {
cook.set('popupopen', 1); //set session cookie
var obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "";
}
}
function hide_popup(id){
cook.set('popupopen', '', -1); //delete cookie
var obj = document.getElementById(id), imsg,
sub = obj.getElementsByTagName('input');
if(sub.length){
sub = sub[sub.length - 1];
} else {sub = false;}
if (obj.style.display == ""){
obj.style.display = "none";
(imsg = document.getElementById('checkPostsMsg')) && imsg.parentNode.removeChild(imsg);
if(sub && sub.disabled){
sub.disabled = false;
sub.className = 'button';
document.getElementsByName('message')[0].value = '';
}
}
}
</script>
</head>
<body onload="if(cook.get('popupopen')){show_popup('contact_form_wrap');}">
<h2>Click image to present Popup</h2>
<br />
<a href="javascript:show_popup('contact_form_wrap')"><img border='1' height='39' width='213' src='http://www.validation.webitry.net/contact-us-button.png' alt="Contact Us"/></a>
<div id="wrapper">
<div id="contact_form_wrap" style="display: none;">
<div id="form_title">Contact Us Form
</div><br />
<?php
if (isset($_POST["check"])) {
$submitted = true;
$mailApproved = check_posts();
//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$message = trim($_POST['message']);
if($mailApproved){
define("EMAIL", "mmmmmmm@gmail.com");
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "A message from the Contact Form";
$email_to = EMAIL;
$todayis = date("l, F j, Y, g:i a") ;
$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Date: " . $todayis . "\n\n";
$emailMessage .= "Message: " . $message;
mail($email_to, $subject, $emailMessage, $header );
}
}
?>
<form id="contact-form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label>Name: <span class="required">Required</span>
<input type="text" name="name" autofocus="autofocus" class="textfield" value="<?php echo htmlentities($name); ?>" />
</label></p>
<p><label>Email: <span class="required">Required</span>
<input type="text" name="email" class="textfield" value="<?php echo htmlentities($email); ?>" />
</label></p>
<p><label>Phone: <span class="required">Required</span>
<input type="text" name="phone" class="textfield" value="<?php echo htmlentities($phone); ?>" />
</label></p>
<p><label>Message: <span class="required">Required</span>
<textarea name="message" class="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label></p>
<p><input type="hidden" name="check" value="c"><input type="submit" value="Send Message"<?php echo $mailApproved? ' class="dbutton" disabled' : ' class="button"'; ?>><a href="javascript:hide_popup('contact_form_wrap')"><span class="X">Close(X)</span></a></p>
</form>
</div>
</div>
</body>
</html>
Bookmarks