tags:

views:

40

answers:

1

Hello. So im holding on making a 2 spliced registration form, now i ran into this ajax request I have to check for if the fields are filled correctly (email and name), before you can continue to other part of the form.

Im very new to ajax requesting, i quite understand a little and have tried myself to work on it, heres what I've done:

index.php:

<input name="full_name" type="text" id="full_name" class="required"> 
Email:
<input name="usr_email" type="text" id="usr_email3" class="required email"> 
</td>
</tr>

<script>
    $("#continue").click(function () {
        $.ajax({
           type: "POST",
           url: "dbc.php?check=First",
           data: "full_name&usr_email",
           success: function(msg){
               alert($err);
            }
         });
         $("#First_1").hide();
         $("#Next_2").toggle();
         return false;
    });
</script>

Now i want First_1 to hide and Next_2 to toggle, IF ONLY it has succeed the control (if output from the request is 1) else then alert with the $err.. Here's dbc.php?check=First

if(isset($_POST['check']) AND $_POST['check'] == 'First') {
    if(empty($_POST['full_name']) || strlen($_POST['full_name']) < 4)
    {
        $err[] = "FEL - Vänligen ange fullständiga namn. Please enter atleast 3 or more         characters for your name";
    }
    if(!isEmail($_POST['usr_email'])) {
        $err[] = "FEL - Invalid email address.";
    }
    if(empty($err)){
        echo 1;
    }
}

How can i make this work, i dont think the data: in ajax request is right..

Update: The form:

form action="index.php?page=checkin" method="post" name="regForm">
 <div id="First_1">
<table width="100%" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            <table cellpadding="0" cellspacing="5">
                                <tr>
                                    <td style="padding: 5px;">
            Fullständiga namn: 
            </td>
            <td>
            <input name="full_name" type="text" id="full_name" class="required"> 
            </td>
            </tr>
            <tr>
            <td style="padding: 5px;">
            Email:
            </td>
            <td>
                <input name="usr_email" type="text" id="usr_email" class="required email"> 
                </td>
                </tr>
                <tr>
                <td style="padding: 5px;">
            Sex: 
            </td>
            <td><select name="sex"><option value="male">Kille</option><option value="female">Tjej</option></select>
            </td>
            </tr>
            <td>            <td>
                        <input type="submit" id="continue" value="Fortsätt">
                        </td></td>
            </table>
            </td>
            </tr>
            </table>
            </div>
<script>
$("#continue").click(function () {
    $.ajax({
       type: "POST",
       url: "dbc.php?check=First",
       data: {full_name : $('#full_name').val()
             usr_email : $('#usr_email').val()},
       success: function(msg){
           if(msg==1){
              $("#First_1").hide();
              $("#Next_2").toggle(); 
           }else{
              alert(msg)
           }               
        }
     });

     return false;
});
</script>

        <div id="Next_2" style="display: none">
        <table width="100%" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            <table cellpadding="0" cellspacing="5">
                                <tr>
                                    <td style="padding: 5px;">
       Lösenord: 
       </td>
       <td>
       <input name="pwd" type="password" class="required password" id="pwd"> 
       </td>
            <td>
            En gång till..
            </td>
            <td>
                    <input name="pwd2" id="pwd2" class="required password" type="password" >
                    </td>
                    <td>
                    <input name="doRegister" type="submit" id="doRegister" value="Register">
                    </td>
</tr>

          </table>
          </td>
          </tr>
          </table>
          </div>
      </form>
+1  A: 
<script>
$("#continue").click(function () {
    $.ajax({
       type: "POST",
       url: "dbc.php?check=First",
       data: {full_name : $('#full_name').val(),
             usr_email : $('#usr_email').val()},
       success: function(msg){
           if(msg==1){
              $("#First_1").hide();
              $("#Next_2").toggle(); 
           }else{
              alert(msg)
           }               
        }
     });

     return false;
});

Christian Smorra
@Christian I think dont the data that are being sended is right, its input fields with the id's full_name and usr_email
Karem
try this version it should have the right data field inside
Christian Smorra
when i press the continue button it just takes me to the form´s action="index.php?page=checkin" page. Please check my question again in one second i will update it with the whole form
Karem
<form action="index.php?page=checkin" method="post" onsubmit="return false;" name="regForm">put this in the first line
Christian Smorra
Now nothing happens when you click the button..
Karem
i found the error it was just a comma that was missing
Christian Smorra