Validate form with default values? - 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: Validate form with default values? (/showthread.php?tid=51033) |
Validate form with default values? - El Forum - 04-18-2012 [eluser]Sven Delle[/eluser] Hi, I'm trying to validate a form which has some default data in the input fields. I've followed the documentation exactly as I can (may be overruled on that one). But I can't seem to invoke ANY of the errors in my callback functions (if I clear both username and password fields i DO get the 'required error', so form_validation seems to be working fine.) Can anyone see why I don't get any errors if the input fields containing the default values? I'm using the HMVC approach in case this matter. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Read other posts on how to extend Form_validation with MY_Form_validation in the /application/libraries, but that changed absolutely nothing. Validate form with default values? - El Forum - 04-18-2012 [eluser]Sven Delle[/eluser] So I: 1: Installed a clean CI 2.1.0. 2: Downloaded and implemented HMVC according to wiki. 3: Extended Form_validation class according to wiki. 4: Went through the Form Validation Tutorial, step by step. Result: Absolutely NO callbacks! What am I doing wrong - I assume I'm doing SOMETHING wrong - otherwise HMVC DO NOT WORK WITH callbacks! This is my Controller: Code: <?php Someone please help me, as I'm in the middle of the night. A was supposed to get things done - not trying to fix things. Validate form with default values? - El Forum - 04-18-2012 [eluser]CroNiX[/eluser] You will have better luck asking this question in the thread created by the HVMC Wiki. Validate form with default values? - El Forum - 04-18-2012 [eluser]Sven Delle[/eluser] OK! Big apologies to all for freaking out in various post about this issue. But I'll post my 'bug' here, as someone else could be doing the same mistake as me. I tried (unintentionally) to have both a 'required' rule and a 'callback_' at the same time (idiot me)! so instead of: Code: $this->form_validation->set_rules('username', 'Username', 'callback_check_username'); I had: Code: $this->form_validation->set_rules('username', 'Username', 'required', 'callback_check_username'); So, make sure your third parameter is the callback (beating myself). There's a couple of hours truly wasted! Hope this post helps someone some day! Validate form with default values? - El Forum - 04-18-2012 [eluser]Sven Delle[/eluser] Is it possible to have both a required and a callback at the same time somehow? If I use a callback to check for existing username I cannot send any errors to the validator if the field is empty. I doesn't validate, but I'd like to send it the required error. Any solution for that? Well, yes: Code: $this->form_validation->set_rules('username', 'Username', 'required|callback_check_default_username'); |