skunk a skunk a - 5 months ago 17
PHP Question

$_POST variables are not set when validate a form with jQuery ajax function

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

When I send my form values to my php files,

var is not set?

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

PHP script is:

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

JS script is :

$( "#signup" ).submit(function( event ) {
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?


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