How to get Post multiple array

(Adi Apriyanto) #1
<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

(Mehdi Achour) #2

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:

(Adi Apriyanto) #3

I got solutions with ajax

    url: $(this).attr('href'),
    type: 'post',
    data: $('#w0').serialize(),
    success: function(data) {

and the controller:

if (Yii::$app->request->isAjax) {
    $data = Yii::$app->request->post();
    return var_post($data->arr)

thanks @machour

(Adi Apriyanto) #4

Another solution I found on the doc

$request = Yii::$app->request; 

// returns all parameters 
$params = $request->bodyParams; 

// returns the parameter "arr" 
$param = $request->getBodyParam('arr');

(Wendy3) #5

Thank you for this code.