3

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 ?

2 Answers 2

2

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];
Sign up to request clarification or add additional context in comments.

2 Comments

I just wondering if there is another way. Something like $this->input->post('var', [0, 1 , 2 etc]); Regarding user guide there is no such way to get data
codeigniter.com/user_guide/libraries/input.html. CI has some of the best docs you will find
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.