Hi all,
I have asked for help concerning a jQuery/PHP contact form previously, but that thread fell idle when no one continued to give suggestions. I've still been working on this and will solve this on my own even if I receive no further replies.
I am seeing a response posted to the div with the id of status, but it is obviously not receiving the correct data input for the e-mail. I have set it up to echo the e-mail address value currently in there, and every time the PHP script is receiving "your e-mail" as the data from that input; therefore, the result echoed is always "Submission Failure- Nothing in Box: your e-mail".
This is the form markup:
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>
The jQuery:
Code:
jQuery(document).ready(function(){
jQuery("#emailbox").submit(function(event){
event.preventDefault();
var ea = $("#go").val();
$.ajax({
url: $(this).attr('action'),
type: $(this).attr('method'),
data: $(this).serialize(),
success: function(response){
$('#status').append(response);
}
});
});
});
emailtester.php
PHP Code:
<?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 $messages;
}
?>
checkfirstsub.php
PHP Code:
<?php
class ProcessEmail
{
public function processor($email)
{
if (!empty($email)){
if ($email != "your e-mail"){
if (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;
}
}
?>
If it helps to figure out why "your e-mail" is being sent to the PHP script, below I've posted a JavaScript snippet that changes the input value from "your e-mail" to blank when the input element is activated.
Code:
function input_focus(obj){
if ( obj.value == obj.defaultValue ){
obj.value = ""
}
}
function input_reset(obj){
obj.value = obj.defaultValue;
}
Hopefully someone can point me in the right direction.