0 Replies - 1769 Views - Last Post: 09 February 2013 - 02:21 PM

#1 etidd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-February 13

Creating Form Script that Shows 2nd Form on Client-Side

Posted 09 February 2013 - 02:21 PM

Hello everyone,

This is my first question here!

I am making an e-mail/mailing list subscription script that shows a 2nd form using jQuery. The processing of the submission, the mailing, & the writing of the submission to the database is all done in PHP. I am having trouble getting the data from one script to another. Right now, I have set jQuery up to call the $.post() method after the This question may also belong in the PHP section if nothing seems to be wrong with the jQuery.

In the following code, I am just trying to return a message that is merely posted to a div with an id of #status that I put on-screen. I just want to see the message returned and printed to the screen.

HTML form markup on home page, index.html:
<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>
<!--
 ...
-->
<div id="status">&nbsp;</div>



emailbox.js
$(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
	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
    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->email, FILTER_VALIDATE_EMAIL))
                return true;
            else 
                return false;
        }
    }
?>



When I click the form submit button on the page, it doesn't do anything at all.

Maybe I should change this first form to get method because I'm only processing one field.

Thanks for any help!

By the way, my website is at worldreviewgroup.com. The form is the orange flag thing on the right side.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1