Form Validation Callback Not Working on Server (but OK on WAMP) - 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: Form Validation Callback Not Working on Server (but OK on WAMP) (/showthread.php?tid=64657) |
Form Validation Callback Not Working on Server (but OK on WAMP) - 50cent - 03-18-2016 Hi all, I've developed a CI site on my local machine using WAMP. I'm using CI 3 with the HMVC extension and it all works fine. I've just uploaded the site to the production server and changed the config files etc to get it working. However, form validation callbacks are not working on the production server. Here's an example from a login form: PHP Code: // Process login form This is the callback function do_login: PHP Code: public function do_login($password) On my local WAMP setup, this all works fine. But on the server PHP Code: $this->form_validation->run($this) To eliminate any errors with the callback function itself, I changed it to the following as a test: PHP Code: public function do_login($password) ... which will obviously always return TRUE, however when $this->form_validation->run($this) is called, even though I changed the do_login callback function to return TRUE, $this->form_validation->run($this) still returns FALSE!! This is driving me crazy and I have no idea why this is happening. It is as if the form validation is ignoring the callback function and just returning false. Can anyone help me? Could it be a setting on the server causing it or something else that could have changed when I uploaded the site files to the server? If it is relevant, on my local machine, within the do_login callback function I had originally set the callback error message like this: PHP Code: $this->form_validation->set_message('do_login', 'User / Pass Incorrect'); ...which worked fine, but on the production server it threw an error stating: "Unable to access an error message corresponding to your field name Password.(do_login)". I had to set the error message in the language file to overcome this. But the fact that this happen on the production server and not on my WAMP setup makes me think there must be some setting or something on the server that is causing this. Anyway, any help is gratefully received. Thanks RE: Form Validation Callback Not Working on Server (but OK on WAMP) - skunkbad - 03-18-2016 Why are you passing $this to run()? RE: Form Validation Callback Not Working on Server (but OK on WAMP) - InsiteFX - 03-18-2016 Did you create and use the MY_Form_valdation.php file for HMVC Callbacks in the libraries folder? PHP Code: <?php RE: Form Validation Callback Not Working on Server (but OK on WAMP) - 50cent - 03-18-2016 Yes I had created the MY_Form_validation file. After much searching and hair pulling, I finally found a solution in the comments of a youtube video! I'll post is here in case anyone else has the same problem. I needed to add the line 'public $CI;' to that file to get it to work on the server. I installed my CI site on 2 different servers and both had the same problem with the callbacks, even though the callbacks were working on my local WAMP setup. Anyway, the full file becomes: PHP Code: <?php Thanks for your suggestions anyway. Now I have a problem with sessions disappearing on the server, but that's another story... RE: Form Validation Callback Not Working on Server (but OK on WAMP) - InsiteFX - 03-19-2016 Right, I posted the main one from my libraries for that I backup I must not had updated it, but yes you need to have public $CI; I have updated my libraries backup to reflect this now. |