Mayur Koshti
Mayur Koshti

Reputation: 1862

How to get all value from the same name of input text fields in codeigniter4?

View

               <?php 
                      $quant_data = array(
                                          'class'       => 'form-control',
                                          'name'        => 'prodquantity[]',
                                          'id'          => 'prodquantity[]',
                                          'placeholder' => 'Enter Product Price',
                                          'type'        => 'number',
                                          'value'       => 250
                                        );

                      echo(form_input($quant_data));

                      if($validation->getError('prodquantity')){                              
                          echo '<span class="text-danger">'.$validation->getError('prodquantity').'</span>';
                      }
               ?>
               <?php 
                      $quant_data = array(
                                          'class'       => 'form-control',
                                          'name'        => 'prodquantity[]',
                                          'id'          => 'prodquantity[]',
                                          'placeholder' => 'Enter Product Price',
                                          'type'        => 'number',
                                          'value'       => 500
                                        );

                      echo(form_input($quant_data));

                      if($validation->getError('prodquantity')){                              
                          echo '<span class="text-danger">'.$validation->getError('prodquantity').'</span>';
                      }
               ?>
              </div>

Controller

$prodquantity = $this->request->getVar('prodquantity');

But getting only 500.

How to get all values it in CI4?

Upvotes: 0

Views: 164

Answers (1)

Khyati Bhojawala
Khyati Bhojawala

Reputation: 182

If we declare the name as an array "[]", while getting the value for a particular name we also write "variableName[]", Please try below code.

$prodquantity = $this->request->getVar('prodquantity[]');

Upvotes: 0

Related Questions