![]() |
Extending Form_validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Extending Form_validation (/showthread.php?tid=57726) |
Extending Form_validation - El Forum - 04-06-2013 [eluser]Unknown[/eluser] Am having trouble extending the Form_Validation class Here is a sample of my code and config <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Form_validation extends CI_Form_validation{ protected $CI; public function __construct($config = array()){ parent::__construct($config); $this->CI =& get_instance(); } function run($module = '', $group = ''){ (is_object($module)) AND $this->CI = &$module; return parent::run($group); } public function validateName($name){ $this->CI->form_validation->set_message('validateName','The %s field must be in text format'); return preg_match('/^(?:[A-Za-z\.\'\-]+(?:\s+|$))$/',$name); } public function validateNumber($number){ if(ctype_digit($number)){ return TRUE; }else{ $this->CI->form_validation->set_message('validateNumber','The %s field must be in numeric format'); return FALSE; } } public function validateAddress($address){ $status = preg_match('/^(?:[0-9A-Za-z\.\'\-]+(?:\s+|$))$/',$address); if($status){ return TRUE; }else{ $this->CI->form_validation->set_message('validateAddress','The %s field must be in alpha-numeric format'); return FALSE; } } public function validateEmail($email){ if(ctype_graph($email)){ return TRUE; }else{ $this->form_validation->set_message('validateEmail','The %s field must be in alpha-numeric format'); return FALSE; } } } <?php $config = array( 'welcome/verifysignup' => array( array( 'field' => 'fname', 'label' => 'First name', 'rules' => 'validateName' ), array( 'field' => 'lname', 'label' => 'Last name', 'rules' => 'required' ), array( 'field' => 'address', 'label' => 'Address', 'rules' => 'required' ), array( 'field' => 'city', 'label' => 'City', 'rules' => 'required' ), array( 'field' => 'zip', 'label' => 'Zip(Postal code)', 'rules' => 'required' ), array( 'field' => 'email', 'label' => 'Email', 'rules' => 'required' ), array( 'field' => 'remail', 'label' => 'Confirm email', 'rules' => 'required' ), array( 'field' => 'remail', 'label' => 'Confirm Email', 'rules' => 'required' ), array( 'field' => 'pphone', 'label' => 'Primary phone number', 'rules' => 'required' ), array( 'field' => 'mphone', 'label' => 'Mobile phone number', 'rules' => 'required' ), array( 'field' => 'username', 'label' => 'Username', 'rules' => 'required' ), array( 'field' => 'pwd', 'label' => 'Password', 'rules' => 'required' ), array( 'field' => 'cpwd', 'label' => 'Confirm Password', 'rules' => 'required' ) ) ); Submitting the form without the first name does not generate an error meaning the custom validateName method is not called. What could be the problem.. Using CI 2.1.3 Please help!!... Extending Form_validation - El Forum - 04-06-2013 [eluser]qICEp[/eluser] Not sure but i think you close more brackets than you open (that lead to errors and failure) Check closing bracket's at the end of the file I also assume that you attached model/controler file in same code tag |