• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unexpected $this->input->post behavior

I'm using an array for my form fields. I've set validation rules according to the manual, and both form_error() and set_value() are working as expected. However, after I submit the form and run the validation successfully, I'm having trouble retrieving the values through the Input class.

When I execute this code:
if ($this->form_validation->run())

I get this result:
  'glist' =>
      'name' => string 'Motorcycle Club' (length=15)
      'gifts' => string '3' (length=1)
      'price' => string '2.50' (length=4)
  'submit' => string 'Ok' (length=2)

  'name' => string 'Motorcycle Club' (length=15)
  'gifts' => string '3' (length=1)
  'price' => string '2.50' (length=4)

boolean false

That is to say, I can retrieve the entire post array, and I can retrieve an array in the post array, but I can't seem retrieve elements from an array in the post array. I've tried various combinations like,
but they all return false.

What is the correct way to retrieve array elements from the post array through the Input class?

$glist = $this->input->post('glist');
echo $glist['name'];

Thanks. I discovered this isn't a Codeigniter issue since you also can't retrieve array elements directly from the $_POST variable.

var_dump($_POST); // this works
var_dump($_POST['glist']); // this works too
var_dump($_POST['glist[name]']); // nope, doesn't work.

The last line of code returns an error:
Quote:Severity: Notice
Message: Undefined index: glist[name]

I'd never run into that because I'd never put arrays on the $_POST variable. Looks like Codeigniter makes you try more adventuresome things. Smile

$data = $this->input->post(NULL, TRUE);

Returns all input post to $data.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.