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”.
<?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.
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.
so your code for checkfirstsub.php look like this below, tested and works for my email account
<?
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;
}
}
?>
when working with classes within php, you need to use $this to access the classes objects from within the class itself. For instance
<?
$animal = new dog;
echo $animal->get_breed();
echo $animal->call_bark();
echo $animal->call_speak();
echo $animal->get_coat();
class dog
{
public $breed = 'Boxer';
public $coat = 'Brindle';
public $speak = 'Wolf';
public $bark = 'Bow Wow Wow';
public function call_bark()
{
return $bark;
}
public function call_speak()
{
return $this->speak();
}
//calling this function will return 'Boxer'
public function get_breed()
{
return $this->breed;
}
//call this function will return an error Undefined Variable
public function get_coat()
{
return $coat;
}
//calling this function set the name of the class object breed.
public function set_breed($set)
{
$this->breed = $set;
return $this->breed;
}
//calling this function will set the variable $coat inside this particular
//function to whatever you set it to but will not affect the class object
//coat. So you will not be getting the desired functionality.
public function set_coat($set)
{
$coat = $set;
return $this->coat;
}
public function speak()
{
return 'Woof Woof';
}
public function bark()
{
return 'Woof Woof';
}
}
?>
Thanks for both of your proposed solutions, especially robawtic.
The actual solution, however, occurred to me. There was an onblur attribute that instantiated one of those JavaScript methods set for that e-mail input, and once you submit your e-mail, it would reset its value to “your e-mail” every time. Removing that onblur attribute has solved the problem.
I should leave this thread open because the next step in this process is processing the second form that I’m about to program to pop up when the submission is successful. I’m sure I’ll stumble across some similar issue at some point.
when executing the onblur you could check if the field is empty. If it is empty you can put your default value back in. When it is not empty, do nothing.