Calling index() on form validation failure - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Calling index() on form validation failure (/showthread.php?tid=66476) Pages:
1
2
|
Calling index() on form validation failure - dbrooke - 10-25-2016 Hello, I'm doing something like this in my controller: PHP Code: if ($this->form_validation->run() == FALSE) { Basically, if form fails, send back to form, if good, then send to "Thank you view". For testing I have added only one set_rules() rule: PHP Code: $this->form_validation->set_rules('f_eventname', 'Event Name', 'required|trim|min_length[3]|max_length[100]|callback_customAlpha'); The action goes to index as expected, but f_eventname always seems to fail, no matter what I put in there. callback_customAlpha is in a helper file that is loaded in the construct function. Anyway, I thought I'd post here to see what you all think as my eyes are "end of day eyes" right now. Thanks, Donovan RE: Calling index() on form validation failure - SomeGuy - 10-25-2016 return $this->index(); RE: Calling index() on form validation failure - salain - 10-25-2016 You cannot use callback if your "customAlpha" is in a helper. As far as I know a callback as to be in the same class as the validation, but not 100% sure as the documentation says controller. In your case you need to use the method describe here: Callable: Use anything as a rule RE: Calling index() on form validation failure - dbrooke - 10-26-2016 Well jump'n gee willikers. I guess I'll have to replicate that function in my various controllers.. as I don't feel like rewriting all the set_rules that are already in place. Would be nice if I could define that function in a global helper via callback_. Thanks for the comments! Donovan RE: Calling index() on form validation failure - salain - 10-26-2016 I have tried with a validation function in a helper You just have change the call to your function. From this PHP Code: $this->form_validation->set_rules('f_eventname', 'Event Name', 'required|trim|min_length[3]|max_length[100]|callback_customAlpha'); to PHP Code: $this->form_validation->set_rules('f_eventname', 'Event Name', Your custom validation function is in an array to allow to set the error message. RE: Calling index() on form validation failure - dbrooke - 10-26-2016 Thanks Salain, I'll give that a shot! RE: Calling index() on form validation failure - dbrooke - 10-26-2016 Salain, that seems to be working for me.. you are missing one ')' I think, but thanks much! <reputation props as well> :-) RE: Calling index() on form validation failure - salain - 10-26-2016 Cool. I know about the missing ) , a wee bit harder to type on a mobile. RE: Calling index() on form validation failure - dbrooke - 10-26-2016 Hmmm, one catch. the array method seems to create a required-like attribute (where as callback_ does not). For example, if I have this: PHP Code: $this->form_validation->set_rules('f_orgcity', 'Organization City', array('trim','max_length[50]', array('customAlpha','customAlpha'))); And I don't put anything in the 'f_orgcity' input field.. It still generates the error. I took another look at the docs and did not see a solution.. is this a bug? Thanks, Donovan RE: Calling index() on form validation failure - salain - 10-26-2016 Hi, I always use an array for the validation rules and I have not add this issue before. You are using the latest version of CI ? What is the error message ? You could add a error message array to the set_rules for "customAlpha" to see if it is failing. PHP Code: $this->form_validation->set_rules('f_orgcity', 'Organization City', Can you post your customAlpha function. |