I'm using the jQuery UI Dialog for the registration of new users on my website. The dialog works fine. However, when I submit the form the AJAX call isn't doing anything. I've searched the web for a while but I can't find a working solution. This is my code at the moment:
var username=$("#username").val();
var password=$("#password").val();
var checkpassword=$("#checkpassword").val();
var email=$("#email").val();
var user_level=$("#user_level").val();
var date_created=$("#date_created").val();
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 500,
width: 600,
modal: true,
buttons: {
"Registreren": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
bValid = bValid && checkLength( username, "username", 3, 16 );
bValid = bValid && checkLength( email, "email", 6, 80 );
bValid = bValid && checkLength( password, "password", 4, 16 );
bValid = bValid && checkLength( checkpassword, "checkpassword", 4, 16 );
bValid = bValid && checkLength( user_level, "user_level", 0, 2 );
bValid = bValid && checkRegexp( username, /^[a-z]([0-9a-z_])+$/i, "error" );
bValid = bValid && checkRegexp( email, "error");
bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "error" );
bValid = bValid && checkRegexp( checkpassword, /^([0-9a-zA-Z])+$/, "error" );
if ( bValid ) {
$.post({
url: 'register.php',
data:
{
username: username,
password: password,
checkpassword: checkpassword,
email: email,
user_level: user_level,
date_created: date_created
}//end data
})//end AJAX post
}//End if
}//End function
}//end buttons
});//end dialog
My form is just a simple HTML input form with the specified ID's
Ex input username:
<form name="registeracc" id="registeracc" action="register.php" method="post">
<input required type="text" id="username" name="username" class="text ui-widget-content ui-corner-all" />
</form>
I've found several "fixes" for this problem on the web, but they dont seem to work for me.
Ex:
data: $('#registeracc :input').serialize(),
error: function(xml, status, error) {
$('#registeracc').html('<p>???</p>');
data: $('#registeracc').serialize(),will serialize the form into name|value pairs. The returned string needs to be used in the right way but I can't see enough of your code to advise.if ( bValid ) {and see if that changes anything. Also check your error console.