Welcome Guest, Not a member yet? Register   Sign In
Does the Validation Class prepare input automatically?
#1

[eluser]prezet[/eluser]
Hi

Just a quick question, in one of my controllers I define form rules and fields like so:

Code:
...

// Define rules
$rules['user_name'] = "trim|required|max-length[30]";

// Set rules
$this->validation->set_rules($rules);

// Set field names
$fields['user_name']    = 'Your Name';

// Set fields
$this->validation->set_fields($fields);

// Run validation
$valid = $this->validation->run();

...

Now if I repopulate the input values of the form with the validated content in the view like so:

Code:
...

$fieldAttr = array(
    'name' => 'user_name',
    'id' => 'user-name',
    'maxlength' => '30',
    'value' => isset( $this->validation->user_name ) ? $this->validation->user_name : ''
    );
    
    echo '<p>' . form_input( $fieldAttr ) . '</p>';

...

It seems to have already prepared the validation content when the form is submitted and the user input is redisplayed in the input's value, i.e. that all double and single quotes are replaced for entities, as are ampersands etc. I thought thats what the likes of form_prep() and $this->validation->prep_for_form() were for?

Is this normal for the validation class?
#2

[eluser]prezet[/eluser]
Ah, would help if I read through the classes and helpers... it's all nicely handled in the Form Helper with form_input.

Loving CI the more I use it. Smile




Theme © iAndrew 2016 - Forum software by © MyBB