Access data from an array of forms using codeigniter

I have this form

<form>
 <input type="text" name="personal_details[]" />
 <input type="text" name="personal_details[]" />

 <input type="text" name="pictures[]" />
 <input type="text" name="pictures[]" />
</form>

With php, I can access data like this

$name    = $_POST['personal_details'][0];
$surname = $_POST['personal_details'][1];
etc.. etc

Is it possible to accomplish this task with the codeigniter input class?

+3
source share
2 answers

They work basically the same.

$personal_details = $this->input->post('personal_details');
$pictures = $this->input->post('pictures');

$name = $personal_details[0];
$surname = $personal_details[1];
+2
source

A form similar to the following, taken from the above example plus some additions.

<form>
 <input type="text" name="personal_details[]" />
 <input type="text" name="personal_details[]" />

 <input type="text" name="pictures[]" />
 <input type="text" name="pictures[]" />

 <input type="text" name="details[first_name]" />
 <input type="text" name="details[last_name]" />
</form>

This can be used in your controller or model as follows.

echo $this->input->post( 'personal_details' )[ 0 ];
echo $this->input->post( 'personal_details' )[ 1 ];
echo $this->input->post( 'pictures' )[ 0 ];
echo $this->input->post( 'pictures' )[ 1 ];

echo $this->input->post( 'details' )[ 'first_name' ];
echo $this->input->post( 'details' )[ 'last_name' ];

I hope this helps. I was interested in doing the same thing and experimenting until I found this solution.

0
source

Source: https://habr.com/ru/post/1787706/


All Articles