jquery formwizard stop form plugin (ajax) after first step
-
18-06-2021 - |
Question
I use jquery form wizard to show a form in two steps. Before proceeding to the second step I use the jquery form plugin to do an ajax validation of the form fields in step 1.
The problem I have is that the complete form is also posted using ajax. Instead of redirecting to another page showing the results, the results are fetched on the same page. How can I configure the form plugin to post the complete form not using ajax?
<script type="text/javascript">
$(function(){
$("#Catering").formwizard({
formPluginEnabled: true,
validationEnabled: true,
focusFirstInput : true,
remoteAjax : {"first" : { // add a remote ajax call when moving next from the second step
url : "/validate",
dataType : 'json',
beforeSend : function(){alert("Starting validation.")},
complete : function(){alert("Validation complete.")},
success : function(data){
if(!(data.geldig)){ // change this value to false in validate.html to simulate successful validation
$("#status").fadeTo(500,1,function(){
$(this).html(data.errormessage)
});
return false; //return false to stop the wizard from going forward to the next step (this will always happen)
}
return true; //return true to make the wizard move to the next step
}
}},
}
);
});
</script>
Solution
If you dont mind expose your variabes throught URL in formoptions you can redirect to anywhere and the variables captured with the form are stored in $.param(data)
So i solved with this part
formOptions: {
success: function(data){ $("#status").fadeTo(500,1,function(){ $(this).html("You are now registered!").fadeTo(5000, 0);
beforeSubmit: function(data){
$("#data").html("data sent to the server: "+ $.param(data) );
/*HERE YOU MADE THE REDIRECTION WITH THE VARIABLES THROUGHT URL*/
window.location.href = "http://www.google.com?"+$.param(data);
},
dataType: 'json'
}
So beforeSubmit all that you are doing is redirect to anypage with the parameters with URL
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow