[eluser]bretticus[/eluser]
Well, I'm a relatively new CI user. Perhaps I was used to doing code similar to Derek, but I have had no qualms using form helper within my views and particularity with dynamically-populated input/controls. I too think that having to make blank rules for inputs that I do not need to validate seems like bloat but considering some of my form validation classes from the past, I'm actually a little bit lighter with CI. I NEVER have html meta data in my controller that gets passed to my view (I'd be interested to see a case for that.) And if I have a commonly used validation, I ALWAYS extend the validation class as to include it in my pipe lists of rules.
Here's a recent example:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*** Brett: Thu Apr 23 16:48:00 GMT 2009
* Extension for adding abitrary error messages and extra rules ***/
class MY_Form_validation extends CI_Form_validation {
function MY_Form_validation($rules=array())
{
parent::CI_Form_validation($rules);
}
function create_arbitrary_error($alias, $message) {
// Save the error message
$this->_field_data[$alias]['error'] = $message;
if ( ! isset($this->_error_array[$alias]))
{
$this->_error_array[$alias] = $message;
}
}
/**
* lowercase
*
* @access public
* @param string
* @return bool
*/
function lower($str)
{
return ( preg_match("/([A-Z])$/", $str)) ? FALSE : TRUE;
}
/**
* lowercase
*
* @access public
* @param string
* @return bool
*/
function phonenumber($str)
{
return ( preg_match("/^\(?[2-9][0-8][0-9]\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/", $str)) ? TRUE : FALSE;
}
}