Doubt i handling formData in Rest and Normal template.
In Controller
public function actionNewStudent()
{
var_dump(Yii::$app->request->post());
$postValue = Yii::$app->request->post();
}
In view controller of angularJs// which invoke on form submission
// on submit function
$scope.submit = function() {
var myUrl = "www.abc.com/v1/..";
var formData = $("#wizard_enrollment_form").serialize();
$http({
method: 'POST',
url: myUrl,
data: formData,
}).success(function (data) {
console.log("Success fully submitted");
}).error(function (data) {
console.log("Something went wrong ... Error .");
});
};
In default template , there is no problem in getting post value, and load the post value in object $model->load($postValue).
and output var_dump(Yii::$app->request->post()) =
array(2) {
["_csrf"]=>
string(56) "a0huX2dDRFYRIl80ICAVARE8JzwzFyslWHpDCCkkcW8CCw0KKC81MQ=="
["Lookup1"]=>
array(10) {
["type"]=>
string(0) ""
}
But in rest controller,
output var_dump(Yii::$app->request->post()) = it throws error , it is not response format,
so , i changed the formData value as
JSON.stringify(formData)
After,
the output of var_dump(Yii::$app->request->post()) is
string(1112) "Lookup1%type%5D=&Lookup1%5Bcode%5D="
$_POST returns the empty array.
so here, i am cant able to use
$model->load(Yii::$app->request->post())
i stuck in this please help.
api config is mentioned like this
'parsers' => [
'application/json' => 'yii\web\JsonParser',
],
and My controller behaviour is
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'new-student'=>['post']
],
],
]);
}
All other functionalities are run without problem using REST, but to submit form is stucked,
In view ,input fields are mentioned as
<input type="text" name="Lookup1[name]" id="lookup1-name" required class="md-input" md-input ng-model="lookup1.name" />
Please help !!! .Thanks in advance.