Welcome Guest, Not a member yet? Register   Sign In
Validation question
#4

[eluser]Michael Wales[/eluser]
You know - I actually had to stop and think about this one. I thought the validation class did correct the post variables, but I wanted to make sure. If you run the following code and enter ' test ' into the field - it will print the string from the view without any of the leading spaces, therefore - the validation class does in fact apply it's functions to the post variables.

For a second there I thought you would have to access them via the validation class. I've always accessed it via the input class and wanted to make sure what I thought to be true, was in fact true.

Controller: test.php
Code:
<?php

class Test extends Controller {

  function index() {
    $this->load->library('validation');
    $rules['string'] = 'trim|required';
    $fields['string'] = 'string';
    $this->validation->set_rules($rules);
    $this->validation->set_fields($fields);
    
    if ($this->validation->run()) {
      // Validation passed
      $data['stuff'] = 'this is' . $this->input->post('string') . 'a test';
      $this->load->view('test', $data);
    } else {
      $data['stuff'] = '';
      $this->load->view('test', $data);
    }
  }

}

?>

View: test.php
Code:
String Result: <?= $stuff; ?>
<?= form_open('test'); ?>
String: &lt;input type="text" name="string" id="string" /&gt;<br />
&lt;input type="submit" value="Submit" /&gt;
&lt;?= form_close(); ?&gt;


Messages In This Thread
Validation question - by El Forum - 08-09-2007, 12:38 PM
Validation question - by El Forum - 08-09-2007, 01:03 PM
Validation question - by El Forum - 08-09-2007, 03:52 PM
Validation question - by El Forum - 08-09-2007, 04:56 PM
Validation question - by El Forum - 08-09-2007, 05:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB