CodeIgniter Forums
CI 1.7 - Form Validation Config File rules are lost if there are additional uri segments - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CI 1.7 - Form Validation Config File rules are lost if there are additional uri segments (/showthread.php?tid=13299)



CI 1.7 - Form Validation Config File rules are lost if there are additional uri segments - El Forum - 11-17-2008

[eluser]JayTee[/eluser]
This isn't really a 'bug' per se, but it cost me 1/2 hour of problem solving:

Scenario:
http://www.example.com/index.php/controller/function/param1

contains a form that posts to itself using the uri_string() function:
Code:
<form action="http://www.example.com/index.php/controller/function/param1">

but your application/config/form_validation.php file shows the rule like this:
Code:
$config = array(
  'controller/function' => array(
    array(
      'field' => 'login',
      'label' => 'Login Name',
      'rules' => 'required'
    ),
    array(
      'field' => 'password',
      'label' => 'Password',
      'rules' => 'required'
    )
  )
);

In this scenario, the validation class will not find the validation rule - because it's looking for a rule called 'controller/function/param1'!

I changed the form so that it posts to the controller's function directly rather than cheating and using the uri segments in lieu of hidden form fields.

I'm sure this is by design; it can also be a 'gotcha' if a user happens to be posting a form to a URL that contains additional uri segments.


CI 1.7 - Form Validation Config File rules are lost if there are additional uri segments - El Forum - 11-19-2008

[eluser]sikkle[/eluser]
Hey JayTee,

i think what your want to confirm is the way user can use $this->form_validation->run('array_name_in_form_validation_config_file');

If you leave it empty he look automatically to guest with the url if not, he look for the index you put there.

I missed that one at first too.

good luck!


CI 1.7 - Form Validation Config File rules are lost if there are additional uri segments - El Forum - 11-19-2008

[eluser]JayTee[/eluser]
I didn't test that particular way - I went with the hidden form field approach and that seems to work OK; I just have to keep in mind what's going on behind the scenes.