1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Rep Power

    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 {
    "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:
          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
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Rep Power
    Here is the jQuery documentation for your jQuery function.


    You should be able to send a variable back from your responseText (from your PHP page) to either display the login lightbox or the registration lightbox.

    If you do not know what I am talking about, if your an AJAX novice; then you might want to read up on how AJAX works and familiarize yourself with some of the basic syntax.

IMN logo majestic logo threadwatch logo seochat tools logo