Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!