Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
put array data to input field and submit that data in model as separate records

I am using code igniter and I have an array which coming from a java script function in view file and I want to get it to a form to save in the db after submitting data.After submitting it is going to controller ->model function using post and then it save after some if conditions.Here my question is how we can get that array into some input fields to pass in post method and how we have to define it.

In view file function

function my_function{
//after some codes

const my_array =[];
}

the output of this array is

0:{a:'1',b:'2',c:'35'}
1:{a:'2',b:'3',c:'34'}
2:{a:'5',b:'1',c:'87'}
3:{a:'4',b:'3',c:'90'}

it should come here in readonly mode

<div class="row">
<div class="col-md-5">
    <input type="text" class ="a" id="a" name= "a" class="form-control name-pull-image">
</div>
<div class="col-md-5">
    <input type="text" class ="b" id="b" name= "b" class="form-control name-pull-image">
</div>
<div class="col-md-5">
    <input type="text" class ="c" id="c" name= "c" class="form-control name-pull-image">
</div>
</div>

And this should be save in db as separate records after clicking submit.

How I can implement this? and how i can pass this to the controller?to take it to the model

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

what exactly your model needed?? I got your question, but am not sure to answer, it's might be wrong. But how about this:

Your html form must be like this, to pass an array to the controller:

<div class="row">
  <div class="col-md-5">
    <input type="text" class ="a" id="a" name= "a[]" value="a" class="form-control name-pull-image">
  </div>
  <div class="col-md-5">
    <input type="text" class ="b" id="b" name= "b[]" value="b" class="form-control name-pull-image">
  </div>
  <div class="col-md-5">
    <input type="text" class ="c" id="c" name= "c[]" value="c" class="form-control name-pull-image">
  </div>
</div>

And get the array when form submitted:

<?php
// your controller...
public function formSubmit() {
    $form_data = [];
    for ( $i=0; $i < count($this->input->post('a')); $++ ) {
        array_push($form_data, [
             'a' => $this->input->post('a')[$i],
             'b' => $this->input->post('b')[$i],
             'c' => $this->input->post('c')[$i],
        ]);
    }
    // result
    print_r($form_data);
}
// other code...
?>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda