Beginner in jquery ajax. I would like to retrieve datas (this part of the job is done and ok) AND to pass them from step1 to step2 of my form.
My code for the moment is : I've tried to show with #step2 #check-ok the place where I want my datas after phase1 display none and phase2 appear but not working : my datas stay on step1.
$(".open1").click(function() {
if (v.form()) {
var data = {
'civility' : jQuery("input[name=civility]:checked", "#to-bc-clt").val(),
'society' : jQuery('#society').val(),
'firstName' : jQuery('#firstName').val(),
'lastName' : jQuery('#lastName').val(),
'email' : jQuery('#email').val(),
};
jQuery.ajax({
url : '/mySite/VerifRep/parsers/check.php',
method : 'POST',
type : 'POST',
data : data,
success : function(data){
if (data != 'passed') {
jQuery('#messages-errors').html(data);
}
if (data == 'passed') {
$(".frm").hide("fast");
$("#step2").show("slow");
$(".open1").css("display","none");
$(".open2").css("display","inline-block");
$("#step 2 #check-ok").val(data);
// Try that way too but not work --> $("#check-ok").html(data);
}
},
error : function(){
alert('Something wrong.'); }
});
}
});
You can use JSON to store the details locally similar to session of php I also had the same problem I had multiple step form and wanted details of step 1 ( plan choices of member ) and use them in function and calculate result and display it in 3rd step where payment was to be done ( cost the plan chosen by that member )
Form should have method POST ( if you use GET , replace POST in php file with GET)
In first step , use JSON like
var x = document.getElementByName(name_of_textbox_which_has_name);
var y = document.getElementByName(name_of_textbox_which_has_age);
var z = document.getElementByName(name_of_textbox_which_has_city);
var val = {name: x, age: y, city: z};
var toBeSent = JSON.stringify(val);
window.location = "phpfilename.php?xyzvar=" + toBeSent;
Put this in a function and call it when user clicks on "Next" button ...
Now , before coming to 2nd step ... In php file ( phpfilename.php ) Remember the variable name was "xyzvar"
<?php
$name=$_POST['xyzvar'];
$data=json_decode($name);
echo $data->name // prints x ( name entered in textbox )
echo $data->age // prints y ( age entered in textbox )
echo $data->city // prints z ( city entered in textbox )
// instead of echo you can use it anywhere for further coding
?>