Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2013, 09:47 PM   PM User | #1
htsmith88
New Coder

 
Join Date: May 2011
Posts: 28
Thanks: 6
Thanked 0 Times in 0 Posts
htsmith88 is an unknown quantity at this point
Exclamation Trying to Create Client-Side E-mail Submission Script

Hello everyone,

I am trying to make a mailing list submission script for my website at worldreviewgroup.com. The first part is to collect and verify an e-mail for the first form and show the next form accordingly. I am using jQuery to do this on the client side while using the .submit() function for the first form with an id of #emailbox. The .post() function returns data run by PHP to access it on the client-side without a page refresh. I want to move the 2nd form on-screen using the jQuery .css() function and render the rest of the elements inactive with a gray mask over everything except the 2nd form. Right now, I'm stuck on the first part attempting to make a complete data loop and getting the results message back to JavaScript successfully and append that results message in an element inside a div with an id of #status, just to simply show that I'm ready for the next step in this project.

form markup:
Code:
      <form id="emailbox" name="form1" method="post" action="Scripts/emailtester.php">
        <div>
          <input type="text" name="emailaddress" id="go" class="emailaddressin" value="your e-mail" onclick="input_focus(this)"  onblur="input_reset(this)" maxlength="60"/>
          <input type="submit" id="emailsubmit" value="Join" />
        </div>
      </form>
emailbox.js
Code:
$(document).ready(function(){
	$("#emailbox").submit(function(event){
		event.preventDefault();
		var ea = $("#go .emailaddressin").val();
		
		$.post(
    		"emailtester.php"
    		, { email_address : ea 
			   , ajax : 1 }
     		, function(data){
				$('#status').html(data);
				showResult(data);
			});
	});
});
emailtester.php
PHP Code:
<?php
    
require_once('checkfirstsub.php');
    
$status 1;
    
$ajax $_POST['ajax'];
    
$messages " ";

    if(
$_POST['go']){
          
$email htmlentities($_POST['go']);
        
$messages '<ul><li>Submission Success</li></ul>';
    } else {
        
$status 0
        
$messages '<ul><li>Submission Failure - Empty Box</li></ul>';
    }

    
$obj_PE = new ProcessEmail();
    if (
$ajax == 1)
        echo 
$obj_PE -> processor($email);
    else {
        
$messages $obj_PE -> processor($email);
?>
<!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="viewport" content="width=device-width, maximum-scale=1.0" />
    <title>Sign Up for the Mailing List at World Review Group</title>
    <script type="text/javascript" src="emailbox.js"></script>
    <script type="text/javascript" src="Scripts/jQuery.js"></script>
</head>
<body>
      <form id="emailbox" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
        <div>
          <input type="text" name="emailaddress" id="go" class="emailaddressin" value="your e-mail" onclick="input_focus(this)"  onblur="input_reset(this)" maxlength="60"/>
          <input type="submit" id="emailsubmit" value="Join" />
        </div>
      </form>
      <h2>Message(s)</h2>
      <?php echo $messages?>
</body>
</html>
<?php ?>
checkfirstsub.php
PHP Code:
<?php
    
class ProcessEmail
    
{
        protected 
$email_address;
        
        public function 
processor($email)
        {
        
$this -> email_address $email;
        
$status 1;

            if (
$email != "your e-mail"){
                    if (
isItAValidEmail($email))
                    {
                        return 
'<ul><li>Submission Successful</li></ul>';
                    } else {
                        return 
'<ul><li>Submission Failure- Invalid E-mail</li></ul>';
                        
$status 0;
                    }
            } else {
                return 
'<ul><li>Submission Failure- Default Value in Box</li></ul>';
                
$status 0;
            }
        }
        
        protected function 
isItAValidEmail()
        {
            if (
filter_var($this->emailFILTER_VALIDATE_EMAIL))
                return 
true;
            else 
                return 
false;
        }
    }
?>
I have been trying to figure this out for so long!
htsmith88 is offline   Reply With Quote
Old 02-07-2013, 04:54 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
First couple of errors I get are in emailtester.php
this line
Code:
if($_POST['go']){
S/B
Code:
if($_POST['email_address']){
and this line
Code:
$email = htmlentities($_POST['go']);
S/B
Code:
$email = htmlentities($_POST['email_address']);
After correcting I get this error from checkfirstsub.php
Code:
if (isItAValidEmail($email))
Try isValidEmail()
That's a start for ya
sunfighter is offline   Reply With Quote
Old 02-07-2013, 05:23 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,641
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No, that function call is incorrect. This: isItAValidEmail($email) should be $this->isItAValidEmail().
Why do you use such an unusual file name for the ProcessEmail class? Not that its really relevant, but would cause huge grief should you change to using autoloaders.

Also, "client" side emailing is a simple mailto: call. This you have is server side; the AJAX does not make it client side it simply makes it's request transparent.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
email submission

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:06 PM.


Advertisement
Log in to turn off these ads.