Welcome Guest, Not a member yet? Register   Sign In
Iterating through a form's $_POST
#10

[eluser]Scott - Beyond Coding[/eluser]
Michael, pyro, Rick.. thanks for all your replies. It's very interesting to see how others tackle the same problem Smile

I often use a similar approach to pyro although I also specify the type of field and then typecast anything that should be an integer or bool.. Something along the lines of this (keeping with the same example variables):
Code:
$fields = array('numbers' => array('catID'),
            'text' => array('cat_name', 'cat_description'));

foreach($fields['text'] as $field)
    $user_input[$field] = $this->input->post($field, true);

foreach($field['numbers'] as $field)
    $user_input[$field] = (int) $this->input->post($field, true);

I think Rick's idea of setting and checking $fields as per the validation library that could be a much neater solution though (as you can set validation rules to handle numbers appropriately etc). Could also cycle through $rules too provided you've set rules for everything Smile


Messages In This Thread
Iterating through a form's $_POST - by El Forum - 08-22-2007, 04:02 PM
Iterating through a form's $_POST - by El Forum - 08-22-2007, 04:13 PM
Iterating through a form's $_POST - by El Forum - 08-22-2007, 11:36 PM
Iterating through a form's $_POST - by El Forum - 08-23-2007, 12:31 AM
Iterating through a form's $_POST - by El Forum - 08-23-2007, 04:53 AM
Iterating through a form's $_POST - by El Forum - 08-23-2007, 11:14 AM
Iterating through a form's $_POST - by El Forum - 08-23-2007, 11:25 AM
Iterating through a form's $_POST - by El Forum - 08-23-2007, 01:21 PM
Iterating through a form's $_POST - by El Forum - 08-23-2007, 04:39 PM
Iterating through a form's $_POST - by El Forum - 08-23-2007, 04:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB