Jump to content

Submitting AJAX signup results

- - - - -

  • Please log in to reply
No replies to this topic

#1
ethikz

ethikz

    Programmer

  • Members
  • PipPipPipPip
  • 112 posts
I have an AJAX form and after someone signs up it validates and then posts to a DB. I am trying to figure out how to email the signup as well. Can I add another action="contact.php" to the form tag?

Any help would be appreciated

Here is the PHP
<?php

if($_GET['action'] == 'signup'){

	

	mysql_connect('localhost','dbuser','dbpass');  

	mysql_select_db('dbname');

	

	$email = mysql_real_escape_string($_POST['signup-email']);

	

	if(empty($email)){

		$status = "error";

		$message = "You did not enter an email address!";

	}

	else if(!preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/', $email)){

			$status = "error";

			$message = "You have entered an invalid email address!";

	}

	else {

		$existingSignup = mysql_query("SELECT * FROM signups WHERE signup_email_address='$email'");   

		if(mysql_num_rows($existingSignup) < 1){

			

			$date = date('Y-m-d');

			$time = date('H:i:s');

			$type = ($_POST['signup-type']);

			

			$insertSignup = mysql_query("INSERT INTO signups (signup_email_address, signup_date, signup_time, signup_type) VALUES ('$email','$date','$time', '$type')");

			if($insertSignup){

				$status = "success";

				$message = "You have been signed up!";	

			}

			else {

				$status = "error";

				$message = "Ooops, There's been a technical error!";	

			}

		}

		else {

			$status = "error";

			$message = "This email address has already been registered!";

		}

	}

	

	$data = array(

		'status' => $status,

		'message' => $message

	);

	

	echo json_encode($data);

	exit;

}

?>


Here is the HTML
<form id="newsletter-signup" action="?action=signup" method="post">

<input type="text" name="signup-email" id="signup-email" class="fieldz" /> 

<input type="image" src="img/submit1.png" class="submitbtn" />

<input type="hidden" name="signup-type" value="Subject1" /></form><br /><p id="signup-response"></p>


<form id="newsletter-signup2" action="?action=signup" method="post">

<input type="text" class="fieldz" name="signup-email" id="signup-email" /> 

<input type="image" src="img/submit2.png" class="submitbtn" />

<input type="hidden" name="signup-type" value="Subject2" /></form><br /><p id="signup-response2"></p>



**Nevermind, I figured it out

Edited by ethikz, 27 September 2011 - 06:51 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users