it's my first post, I'm stuck on this, please help.
On a page I've got two symfony forms (without classes) from which I get some data that I store in arrays. The first form is for a contract, and the other form is used to fill a datatable of products with their data (price, quantity, etc.). On each of those forms, I've got a submit button that I manage with ajax (onclick) to get to the step forward of the pagen while preventing the data processing. The datatable listing the products is the ending step of the page and under it I have a validation button that I want to use to submit all the data from the 1st form and the datatable (in which are the data from the second form) that I previously have stored in arrays.
I know two ways of doing this ($.post with jQuery and the other with ajax but both don't work). I manage to redirect to the other page but I can't get the $_POST (or $request) data.
Here's the 'final button' ajax part (with the other way I tried in comments) :
$("#btn_final").click(function( e ) {
// console.log(produits);
// $.post(
// path_confirm,
// { produits: produits },
// function() {
// window.location.replace(path_confirm);
// }
// );
$.ajax({
url: path_confirm,
type: 'POST',
// dataType: 'html',
data: { 'produits' : produits, 'contrat' : contrat },
// context: this,
// dataType: "json",
success:function(data) {
window.location.replace(path_confirm);
// console.log(data);
},
error:function(data) {
alert("erreur");
}
});
and here's my basic controller supposedly getting the data :
public function getData(Request $request) {
// $produits = $request->request->get('produits');
// $contrat = $request->request->get('contrat');
if ($_POST) {
var_dump($_POST);die;
} else {
echo "<h1> no data :/ </h1>";die;
}
I get redirected to the page but the answer is "no data". Thank you in advance for your help.
produitsandcontratdefined?data: { 'produits' : produits, 'contrat' : contrat }