Welcome Guest, Not a member yet? Register   Sign In
set_value() not producing values that are present in $_POST?
#1

[eluser]wrd[/eluser]
I may be fundamentally misunderstanding something here; I'm very new to CI.

Some test code:

Code:
$form_rules = array(array('field'   => 'customer_first_name',
                                  'label'   => 'First Name',
                                  'rules'   => 'required'),
                            array('field'   => 'customer_last_name',
                                  'label'   => 'Last Name',
                                  'rules'   => 'required'),
                            array('field'   => 'customer_address1',
                                  'label'   => 'Address',
                                  'rules'   => 'required'),
                            array('field'   => 'customer_city',
                                  'label'   => 'City',
                                  'rules'   => 'required'),
                            array('field'   => 'customer_state',
                                  'label'   => 'State',
                                  'rules'   => 'required'),
                            array('field'   => 'customer_zip',
                                  'label'   => 'Zip Code',
                                  'rules'   => 'required'),
                            array('field'   => 'customer_phone',
                                  'label'   => 'Phone',
                                  'rules'   => 'required'),
                            array('field'   => 'customer_email',
                                  'label'   => 'Email Address',
                                  'rules'   => 'valid_email'));
        $this->form_validation->set_rules($form_rules);
        echo '<pre>';
        print_r($_POST);
        echo '</pre>';
        foreach ($form_rules as $field) {
            echo $field['field'] . ': ' . set_value($field['field']) . '<br>';
        }

So if I fill out only two fields -- first and last name -- I would expect to see those two values appear both in the $_POST dump and in the $form_rules echoes. Instead, the set_value() function does not seem to be producing any values:

Code:
Array
(
    [customer_title] => none
    [customer_first_name] => William
    [customer_last_name] => Dickson
    [customer_address1] =>
    [customer_address2] =>
    [customer_city] =>
    [customer_state] => MO
    [customer_zip] =>
    [customer_phone] =>
    [customer_email] =>
    [submit] => Continue
)
customer_first_name:
customer_last_name:
customer_address1:
customer_city:
customer_state:
customer_zip:
customer_phone:
customer_email:

I had intended to use it like so:

Code:
$field_attributes = array('name'    => 'customer_first_name',
                                  'id'      => 'customer_first_name',
                                  'maxlength'   => '25',
                                  'size'        => '25',
                                  'value'       => set_value('customer_first_name'));
        $this->data['form'] .= form_label('First Name');
        $this->data['form'] .= form_input($field_attributes);

Any thoughts as to what I'm doing wrong? Thanks!
#2

[eluser]llogo[/eluser]
Maybe your not running the checking to do that u need to use: $this->form_validation->run() , in the function that recieves the $_POST, this will check the fields of the $_POST and will return TRUE if everything is ok, if not u can use the set_value() to repopulate ur form.
#3

[eluser]wrd[/eluser]
That was it; I was running it, but not in the right place. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB