Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    28
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,449
    Thanks
    23
    Thanked 630 Times in 629 Posts
    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

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •