How validation works and its callback function in Code Igniter
Validation framework in the Code Igniter is pretty powerful, i have to admit that once you get around to use it, eventually it can save lots of web development time, and it's much more secure rather than building it up yourself. CI provides a number of commonly used validation rules such as "required fields", "numeric fields", "alpha fields", and many others. Additionally, you can build up your own custom validation function by using callback. A comprehensive user guide from Code Igniter in regard to form validation is available here.
Notice: This Code Igniter is using version 1.6.3, there is currently a much newer version 1.7.2, and it's using a new form validation class instead, just a warning that the below code is dedicated solely for CI version 1.6.3 and below.
The sample code below will elaborate how CI validation works around the clock:
/* Validation method for current, new and confirm password field */ function _set_validation_password($adminid) { $rules['c_password'] = "required|min_length[6]|callback__password_check[$adminid]"; $rules['n_password'] = "required|min_length[6]|matches[passconf]"; $rules['passconf'] = "required"; $this->validation->set_rules($rules); $fields['c_password'] = 'Current Password'; $fields['n_password'] = 'New Password'; $fields['passconf'] = 'Confirm Password'; $this->validation->set_fields($fields); $this->validation->set_error_delimiters('<span style="color: teal; font-size: 11px;">', '</span>')<span style="color: teal; font-size: 11px;"> </span>; }
A couple of things to note:
| "required", "min_length[x]" are default validation rules from the Code Igniter framework. | |
| callback__password_check is a custom validation function to accomodate your own need. | |
| $rules should be filled with your preferred validation rules. | |
| $fields should be filled with field name what should come up on validation error message. | |
| $this->validation->set_error_delimiters will enclose the validation error message with your custom css. | |
| the underspace symbol (_) in front of function name means the function is private and cannot be called from the URL address alone. | |
| the callback function always has to be in "callback_" format with underspace symbol at the end. |
/* Check into database whether the input for current password is valid or not */ function _password_check($current_password, $adminid) { $result = $this->oAdmin->check_password($current_password, $adminid); if($result->num_rows() == 0) { $this->validation->set_message('_password_check', 'Current password is invalid'); return FALSE; } else { return TRUE; } }
A couple of things to note:
| $this->oAdmin->check_password is a model function to check the database to ensure whether the current user password is valid or not. | |
| $this->validation->set_message will set your error message when the validation fails. |
function change_password() { $this->_set_validation_password($this->session->userdata('adminid')); if($this->validation->run() == FALSE) { // do something if the validation doesn't pass } else { // do something if the validation passes } }
A couple of things to note:
| $this->_set_validation_password will set the following validation function as default. | |
| $this->validation->run() will execute the form validation function set as above. |

Comments
Hi, i think you’ve made some
Hi, i think you’ve made some truly interesting points. Not too many people would actually think about this the way you just did. I’m really impressed that there’s so much about this subject that’s been uncovered and you did it so well, with so much class. Good one you, man! Really great stuff here.N10-004 exam// 70-642 exam// 640-801 exam// 640-822 exam// CISSP exam// 350-001 exam// 70-647 exam// PMI-001 exam//
Hi, i think you’ve made some
Hi, i think you’ve made some truly interesting points. Not too many people would actually think about this the way you just did. I’m really impressed that there’s so much about this subject that’s been uncovered and you did it so well, with so much class. Good one you, man! Really great stuff here.Vmware exam// pmp exam// oracle exam// 640-802 exam// 70-640 exam// 70-680 exam// SY0-201 exam// VCP-410 exam//
efix Solution
<a href=" http://efix.co"> eFix </a>Call eFix @ 0-808-189-0441 for comprehensive tech support from eFix certified technicians. eFix provide support for maintenance, troubleshooting errors, setup and installation of software, We are available 24/7/365 days.
Hello there! This is my first
Hello there! This is my first comment here so I just wanted to give a quick shout out and tell you I genuinely enjoy reading through your articles. Can you recommend any other blogs/websites/forums that deal with the same subjects? Thanks a ton!Pass4sure F50-531 Pass4sure 640-721 Pass4sure 642-457 Pass4sure 350-029 Pass4sure SK0-003 Pass4sure 642-427 Pass4sure 642-165 Pass4sure JN0-343
efix Solution
<a href=" http://fusoft.org/dell-support.html"> Dell Support </a>Get Dell support for all Dell Products with Fusoft technicians just call us at 1-888-804-1696. Avail excellent help and support for dell models.<a href=" http://fusoft.org/acer-support.html"> Acer Support </a>We provide 24x7 comprehensive tech support for Acer products like Computer, Desktop, Printers, Drivers. Just Call us @ 1-888-804-1696 for Acer Technical Support and Help.<a href=" http://fusoft.org/windows-7.html"> Windows 7 Support</a>Get Windows 7 support from fusoft certified tech experts just call @ 1-888-804-1696 and our tech experts will help you to fix all issue related to Windows 7.
Get Dell support for all Dell
Get Dell support for all Dell Products with Fusoft technicians just call us at 1-888-804-1696. Avail excellent help and support for dell models.e provide 24x7 comprehensive tech support for Acer products like Computer, Desktop, Printers, Drivers. Just Call us @ 1-888-804-1696 for Acer Support and Help.Get Windows 7 support from fusoft certified tech experts just call @ 1-888-804-1696 and our tech experts will help you to fix all issue related to Windows 7.
Get Dell support for all Dell
Get Dell support for all Dell Products with Fusoft technicians just call us at 1-888-804-1696. Avail excellent help and support for dell models.e provide 24x7 comprehensive tech support for Acer products like Computer, Desktop, Printers, Drivers. Just Call us @ 1-888-804-1696 for Acer Support and Help.Get Windows 7 support from fusoft certified tech experts just call @ 1-888-804-1696 and our tech experts will help you to fix all issue related to Windows 7.
Error 0xC004C032 of Office
Error 0xC004C032 of Office 2010 in Windows 7 This Bolg Provide a complete Solution to all Office 2010 problems that occur while working on Office 2010.Fix Error Code 0x8007232b for Windows 7 This Bolg Provide a complete Solution to all Office 2010 problems that occur while working on Office 2010.Outlook Express help for errors while importing and exporting messages This Bolg Provide a complete Solution to all Outlook problems that occur while working on outlook.Outlook express error 0x800ccc90 This Bolg Provide a complete Solution to all Outlook problems that occur while working on outlook.firefox crashing, hangs, not responding problem This Bolg Provide a complete Solution to all Internet browser problems that occur while working on Internet.504 Gateway Timeout Error This Bolg Provide a complete Solution to all Internet browser problems that occur while working on Internet.
windows vista support
Fix exception code c0000005 : This Blog Provide a complete Solution to Microsoft Vista operating system problems that occur while working on Microsoft Vista and exception code c0000005 particularly.What is 0XC01A001D Error and How to fix it : This Blog Provide a complete Solution to Microsoft Vista operating system problems that occur while working on Microsoft Vista and What is 0XC01A001D Error and How to fix it particularly.How to fix 0×800106ba Windows Defender Error : This Blog Provide a complete Solution to Microsoft Vista operating system problems that occur while working on Microsoft Vista and How to fix 0×800106ba Windows Defender Error particularly.What is 0XC01A001D Error and How to fix it : This Blog Provide a complete Solution to Microsoft Vista operating system problems that occur while working on Microsoft Vista and What is 0XC01A001D Error and How to fix it particularly.How to fix 0xc000003a error in vista</a>This Blog Provide a complete Solution to Microsoft Vista operating system problems that occur while working on Microsoft Vista and How to fix 0xc000003a error in vista particularly.How to Fix 0xC0000221 error in vista : This Blog Provide a complete Solution to Microsoft Vista operating system problems that occur while working on Microsoft Vista and How to Fix 0xC0000221 error in vista particularly.How to Fix Incorrect Funtion 0x80070001 error in vista : This Blog Provide a complete Solution to Microsoft Vista operating system problems that occur while working on Microsoft Vista and How to Fix Incorrect Funtion 0x80070001 error in vista particularly.
Good post,I like it.If you'd
Good post,I like it.If you'd like to get your perform published around the tattoo laser removal machine Artists' Guild website you then must first join the Guild by registering. But MailOnline can reveal all isn't quite as it seems using the story of 'Rossie Brovent's poo laser tattoo removal machine'.The resident of Dayton, Ohio, was reportedly suing her ex-boyfriend and temporary tattoo sleeves artist Ryan Fitzjerald for $100,000 on the drawing which she eventually found was of flies over a pile of excrement.