<input type="hidden" name="arr[]" value="1"/>
<input type="hidden" name="arr[]" value="2"/>
<input type="hidden" name="arr[]" value="3"/>
im trying to get with Yii::$app->request->post(‘arr’) but empty results
<input type="hidden" name="arr[]" value="1"/>
<input type="hidden" name="arr[]" value="2"/>
<input type="hidden" name="arr[]" value="3"/>
im trying to get with Yii::$app->request->post(‘arr’) but empty results
It should work. Is your form configured to do a POST? (ie. method="post"
)
When you use your browser inspector, how do you see the value being sent?
Look for something like this:
I got solutions with ajax
$.ajax({
url: $(this).attr('href'),
type: 'post',
data: $('#w0').serialize(),
success: function(data) {
console.log(data);
}
});
and the controller:
if (Yii::$app->request->isAjax) {
$data = Yii::$app->request->post();
return var_post($data->arr)
}
thanks @machour
Another solution I found on the doc
https://www.yiiframework.com/doc/guide/2.0/en/runtime-requests
$request = Yii::$app->request;
// returns all parameters
$params = $request->bodyParams;
// returns the parameter "arr"
$param = $request->getBodyParam('arr');
Thank you for this code.