开发者

Accessing data from form array with codeigniter

开发者 https://www.devze.com 2023-02-06 10:20 出处:网络
I have a form like this <form> <input type=\"text\" name=\"personal_details[]\" /> <input type=\"text\" name=\"personal_details[]\" />

I have a form like this

<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 do this task with codeigniter input class ?


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];


A form like the following, taken from the example above 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 within your controller or model like the following.

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 that this helps. I was wondering the same thing and experimented until I found this solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消