
October 23rd, 2012, 11:30 AM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 1
Time spent in forums: 2 m 52 sec
Reputation Power: 0
|
|
|
Help with Ajax Forms
I'm using PHP and Ajax to implement some forms. I got the PHP part working but am having a hard time on the Ajax part.
I have a login form that checks for the user's email address.
Here's the PHP code to check if an email address exists in the db.
PHP Code:
//connect to db
//query db
if(mysql_num_rows($result) > 0) {
//echo "true"; //email exists in db redirect user to logged in page
header ("loggedin.html");
exit ();
} else {
echo "false"; //email doesn't exist in db show user registration form
}
If email exists in db I redirect the user to the logged in page. If it doesn't exist I want them to fill out a registration form. But, I want to display the registration form in a jQuery lightbox.
1. Can I have both (login and registration forms) on the same page? I would set the registration form to display none then on submit if the email doesn't exist I would then call the jquery lightbox to open the registration form. Is this possible?
2. How do I pass that "email doesn't exist" to Ajax? I'm not sure how PHP/Ajax interact. This is where I'm stuck. Any help is appreciated.
Here's the JS:
Code:
$(document).ready(function(){
$.ajax({
type: "POST",
url: "index.php", // the page where both my login and registration form live?
data: value,
success: function()
{
// not sure what to do here
}
});
});
|