Hi Dave, and thanks for your reply. Great post.
I'm still not doing it right!!!

I'm not using an array to pass data back and forth, my form method is set to "get", I'm not working on processing the second form (yet), among some other little nuances that differentiate my script from yours, but something is incorrect with what I tried.
Currently, when I submit the form, the page does nothing (no page refresh, no redirection, nothing). It does not matter if it is a valid submission or not.
Maybe someone knows what I have done incorrectly.
The JS file:
Code:
//this function is called by the AJAX method to handle the PHP script results
function testFirstResults(response){
if (response.indexOf("Submission Successful") != -1){
$('<div>',{ id : 'blackoverlay' }).insertBefore('#submissionform');
$("#submissionform").css("display", "block");
$("#submissionform").center();
} else if (response.indexOf("Invalid E-mail") != -1){
//display error
} else if (response.indexOf("Nothing in Box") != -1){
//do nothing
} else {
//do nothing
}
}
// Overlay Effect Script for E-mail Submission Form
jQuery.fn.center = function () {
this.css("position", "absolute");
this.css("top", ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + "px");
return this;
}
$(document).ready(function(){
$("#emailbox").submit(function(e){
$.ajax({
type: $(this).attr('method'),
dataType: 'json',
cache: false,
url: "emailtester.php",
data: $(this).serialize(),
success: function(data){
testFirstResults(data);
}
});
e.preventDefault();
});
});
HTML Code:
HTML Code:
<form id="emailbox" name="form1" method="get" action="Scripts/emailtester.php">
<div>
<input type="text" name="email" id="go" value="your e-mail" onclick="input_focus(this)" onblur="input_reset(this)" maxlength="60"/>
<input type="submit" id="submit" value="Join" />
</div>
</form>
CSS styles:
Code:
#submissionform{
background:url("emailsubmission.gif") no-repeat scroll 50% 0 transparent;
width:360px;
height:280px;
position:absolute;
display:none;
top:500px;
right:460px;
z-index:9;
padding:60px 10px 0 45px;
text-align:left;
}
#blackoverlay{
display:block;
position:absolute;
top:0%;
left:0%;
width:100%;
height:100%;
background-color:black;
z-index:8;
-moz-opacity: 0.8;
opacity:.80;
filter:alpha(opacity=80);
}
The PHP scripts:
PHP Code:
/* emailtester.php */
<?php
require_once('checkfirstsub.php');
$email = $_GET['email'];
if (!isset($email) || $email == "your e-mail")
echo '<p>Submission Failure - Nothing in Box: ' . $email . '</p>';
else {
$email = htmlentities($email);
$obj_PE = new ProcessEmail();
$messages = $obj_PE -> processor($email);
echo json_encode($messages);
}
?>
/* checkfirstsub.php */
<?php
class ProcessEmail
{
public function processor($email)
{
if (!empty($email)){
if ($email != "your e-mail"){
if ($this -> isItAValidEmail($email))
{
return '<p>Submission Successful</p>';
} else {
return '<p>Submission Failure- Invalid E-mail</p>';
}
} else {
return '<p>Submission Failure- Default Value in Box</p>';
}
} else {
return '<p>Submission Failure- Nothing in Box</p>';
}
}
public function isItAValidEmail($email)
{
if (filter_var($email, FILTER_VALIDATE_EMAIL))
return true;
else
return false;
}
}
?>
Bookmarks