Here is the code in the email_list admin controller page:
$idOfCourse = $this->request->data('courseId'); /* In these 2 lines I am reading the data posted from the Js page*/
$emailArray = $this->request->data('emailList');
This is the ajax code in the corresponding JS
`var data = {
courseId : id,
emailList: myArray
}; //here I am formatting in JSON form with 2 fields courseID and emailList
$.ajax({ //here I am giving the call
type:"POST",
url :"/adata/admin/email_list",
data: { studentcoursemaildata : data, action : "/adata/admin/template1"}
}).done(function(){
window.location.href ="/admin/email/"; /*I am redirecting after the data is being fetched */
});
`
The key to the correct solution is good understanding of how to access the data formatted in JSON.
First we have to read the studentcourseemaildata because that’s what contains the whole data.
it will be read like this inthe controller-:
$someVariable = $this->request->data(‘studentcourseemaildata’); After doing this in the appropriater controller we get an array. From which reading the corresponding constituent field is straightforward and can be done like this:
idOfTheCourse = $someVariable(‘courseId’);
$mailArray = $someVariable[’emailList’];
That’s It.