![]() |
"Unable to find validation rules" error after redirect - 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: "Unable to find validation rules" error after redirect (/showthread.php?tid=63114) |
"Unable to find validation rules" error after redirect - federico - 09-28-2015 Hello. I am trying to implement the post-redirect-get pattern, here's my problem (I think it could be a bug): post -> redirect (to same controller) -> "Unable to find validation rules" I perform redirecting using this line of code: PHP Code: redirect(current_url(), 'location', 302); if I don't redirect: post -> form_validation->run() -> everything works as expected. forgot to say: i'm using CodeIgniter Version 3.0.1 RE: "Unable to find validation rules" error after redirect - Martin7483 - 09-28-2015 You post your form to a URL and from that URL you redirect to that same URL? So reloading the page to it's original state? RE: "Unable to find validation rules" error after redirect - Narf - 09-28-2015 It's not a bug ... you cannot reasonably expect the framework to somehow maintain an object's state between two separate requests - that's two separate processes. I suspect you just don't quite understand the PRG pattern and you don't need a redirect in the first place, similarly to this guy here: https://github.com/bcit-ci/CodeIgniter/issues/2903 RE: "Unable to find validation rules" error after redirect - PaulD - 09-28-2015 lol. I love reading your posts Narf, they are so funny in their precision and brevity. Quote:Precisely - you're in the minority, because it's wrong. Best wishes, Paul. RE: "Unable to find validation rules" error after redirect - federico - 09-28-2015 (09-28-2015, 06:46 AM)Narf Wrote: It's not a bug ... you cannot reasonably expect the framework to somehow maintain an object's state between two separate requests - that's two separate processes. Form validation rules are loaded from the config file everytime .. so I can't understand why it should be unable to find validation rules Anyway.. 1 - If I normally visits the page w/o posting, no error is shown in the logs 2 - If I submit data w/o any redirects everything works (no errors again) If I submit data then redirect, I would expect that It works as if I didn't post anything problem is it seems I get that "Unable to find validation rules" only if I redirect after a post. p.s. I set csfr protection temporarily off during theese tests just in case p.p.s I was doing this just because I hoped i could extend, let's say, Form_validation class, to automatically redirect posts without doing it manually RE: "Unable to find validation rules" error after redirect - Narf - 09-28-2015 (09-28-2015, 07:44 AM)PaulD Wrote: lol. I love reading your posts Narf, they are so funny in their precision and brevity. Yea, I'm not really proud with that one actually ... and let's keep this on topic please. (09-28-2015, 10:25 AM)federico Wrote:(09-28-2015, 06:46 AM)Narf Wrote: It's not a bug ... you cannot reasonably expect the framework to somehow maintain an object's state between two separate requests - that's two separate processes. Well, for starters - it doesn't know where you're redirecting from. But that's not the point; I'm not saying it's impossible, I'm saying you shouldn't expect it to do that. Please post the code if you need help with resolving whatever the problem is ... I'm sure it's just a logical error. RE: "Unable to find validation rules" error after redirect - mwhitney - 09-28-2015 (09-28-2015, 10:25 AM)federico Wrote: Form validation rules are loaded from the config file everytime .. so I can't understand why it should be unable to find validation rules I did a quick search in the form_validation library and found the error message 'Unable to find validation rules'. I think this is just a case of a misleading error message, or a difference in the way the code is checking for the existence of data to validate in two different methods. When you call run():
PHP Code: public function set_rules($field, $label = '', $rules = array(), $errors = array()) while run() just does this: PHP Code: public function run($group = '') So, when you redirect, $this->CI->input->method() !== 'post' and you didn't use set_data(), so $this->validation_data is empty, and set_rules() exits and run() thinks it didn't find any rules, when it really just didn't find any data. RE: "Unable to find validation rules" error after redirect - federico - 09-29-2015 Thank you mwhitney, clear explanation |