Hi All. I have been struggling with a form wizard all day. I'm using jquery stepy (form wizard) along with validation plugin.
To cut a long story short, my first step is to get MySQL connection from form controls details. On submit ('next' button) a check is made on an empty hidden control ('hid').
rules: {
hid: {
required: function(){
return checkDBData();
},
messages: {
hid:
{required: 'SQL not available'},
...(etc)...
So, if the function checkDBData passes, false should be returned, so that the form can progress to the next step. If the connection details fail, true is returned so that an error msg is posted.
Here's the checkDBData function:
function checkDBData(){
var host = $('#mysql_host').val();
var username = $('#username').val();
var password = $('#password').val();
var dbname = $('#dbname').val();
$.post( "install/sqlcheck.php",
{"host": host,"username": username, "password": password, "dbname": dbname},
function(msg){
if(msg.required == false){
return false;
}else{
return true;
}
},
"json"
);
}
the return values don't find their way back to the rules. However, if I hard code false and true to the function...
function checkDBData(){
var host = $('#mysql_host').val();
var username = $('#username').val();
var password = $('#password').val();
var dbname = $('#dbname').val();
$.post( "install/sqlcheck.php",
{"host": host,"username": username, "password": password, "dbname": dbname},
function(msg){
if(msg.required == false){
return false;
}else{
return true;
}
},
"json"
);
return false; //or return true for testing purposes
}
This works.
I assume it's due to the asynchronous nature of the ajax call. Any ideas?