Issue with Validation library |
[eluser]awpti[/eluser]
Okay, running the latest - 1.6.3 Problem: http://ignitedjobs.com/addjob/ Explanation: Following the examples in the User Guide results in notices that $this->validation->...var here... is not set. This goes away if I submit with even just one field filled in. I tried to avoid it by abusing ternary operators (yuck to that attempt), but I just can't figure out the cause. According to the UG, this is how it should be done. The Controller: Code: function validate() The View: Code: if($this->validation->error_string) { echo '<div class="notlive"><p>'.$this->validation->error_string.'</p></div>'; }
[eluser]awpti[/eluser]
You can see it right off the linked site. A PHP Error was encountered Severity: Notice Message: Undefined property: CI_Validation::$email Filename: views/add_job.php Line Number: 10 ... and so on and so forth for each $this->validation->property Note: If you fill in any single field and submit it, they no longer appear.
[eluser]hvalente13[/eluser]
[quote author="awpti" date="1215792094"]You can see it right off the linked site. A PHP Error was encountered Severity: Notice Message: Undefined property: CI_Validation::$email Filename: views/add_job.php Line Number: 10 ... and so on and so forth for each $this->validation->property Note: If you fill in any single field and submit it, they no longer appear.[/quote] Hi Awpti, Have you loaded the class in the controller that loads the view, at first time? Good luck
[eluser]awpti[/eluser]
Was in laughlin for the weekend, slow reply here. The Validation library is loaded with the config/autoload.php
[eluser]gon[/eluser]
What I do is extending Validation library by putting this code in a file called MY_Library, in application/libraries Only works for PHP5: Code: class MY_Validation extends CI_Validation { You can then write $this->validation->whatever, and $this->validation->whatever_error even if validation hasn't been run.
[eluser]hvalente13[/eluser]
Can you post the code of the controller that loads the form for the first time?
[eluser]gon[/eluser]
The code is just as usual: For example, the typical controller function: Code: function index() { And the form view would be just like in the docs examples. The trick is that by using the library extension I posted, there won't be erros reporting that values hasn't been initialized for the validation object, even if validation hasn't been run.
[eluser]Colin Williams[/eluser]
Very odd. Your code looks fine. And the set_fields() method already does what gon does in his extension: Code: foreach($this->_fields as $key => $val) You can clearly see that $this->validation->field is either '' or the posted value, but never undefined.. I'm at a loss, cause I have very similar code in a 1.6.3 site right now that isn't throwing errors.
[eluser]hvalente13[/eluser]
Hi, The problem is... if the fields and rules for validation haven't been initialized, then that error occurs Code: $rules = array That happens because the validation controller it's not the same that the one that loads the form view at first time... The philosophy of validation class is that it's only needed one controller to initialize and validate the all form and process... Give it a try! |
Welcome Guest, Not a member yet? Register Sign In |