0

I have a html form and a jQuery function to validate my form.

When I send my form values to my php files, $_POST var is not set?

<form id="signup" class="dialog-form" action="bat/new_user.php" method="post">
    <div class="form-group">
        <label>E-mail</label>
        <input type="text" name="mail" placeholder="[email protected]" class="form-control">
    </div>
    <div class="form-group">
        <label>Password</label>
        <input type="password" name="password" placeholder="My secret password" class="form-control">
    </div>
    <input type="submit" class="btn btn-primary">
</form>

PHP script is:

if (isset($_POST["mail"])) 
{
    $mail = $_POST["mail"];
    print $mail;}
    else{print "ko";
}

JS script is :

$( "#signup" ).submit(function( event ) {
            event.preventDefault();
          var $form = $( this ), url = $form.attr( "action" );
         console.log($form.serialize() );
          var posting = $.post( url, { s: $form.serialize() } );
          posting.done(function( data ) {
            $( "#register-dialog" ).append( data );
          });
        });

How I can get the form values?

1
  • Try: $_POST["s"]["mail"]; see your jquery code puts everything in object s Commented Oct 24, 2014 at 14:29

1 Answer 1

3

The problem is the data passed to post(), it should be

var posting = $.post(url, $form.serialize());

You are passing a parameter called s with value as the serialized form

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.