JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 7th, 2013, 04:06 PM
etidd etidd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Location: Atlanta, GA, USA (unfortunately)
Posts: 49 etidd User rank is Private First Class (20 - 50 Reputation Level)etidd User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 44 m 50 sec
Reputation Power: 5
Send a message via Skype to etidd
Lightbulb Creating Client-Side Code to Handle Mailing List Subscription

Hello all,

I'm trying to use jQuery to show and hide menus depending on whether the PHP code it references through the $.submit() or $.post() functions says that the submission is valid or invalid. All I'm trying to find out with this beginning is whether I'm able to return anything and make anything happen with PHP or JS or... something is not working! When I click the submit button on the first form, nothing happens on the page.

form markup on home page, index.html:
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="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;
        }
    }
?>


Why am I not seeing a message posted inside the div with the id of status? That div is right in the middle of the screen (I positioned it in CSS), with a background image, but I'm not seeing any message submitted back to jQuery and posted to that div#status.

Here are some screenshots of what I'm trying to accomplish:
First Part, Home Page Normal without Email Submitted Yet
After the Email is Submitted Successfully, it will Show the Next Form with a Gray Mask over the Rest of the Content
Error Messages Appear in Red Text if 2nd Form Not Successfully Submitted
Submission Success


Thanks for all your help!

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Creating Client-Side Code to Handle Mailing List Subscription

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap