CodeIgniter Forums

Full Version: Form_validation run() method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Greetings!

I've been reading the Form_validation implementation,
and wondering why does the run() method return FALSE if there is not any rule set.

Wouldn't the opposite (return TRUE unless some rule is not attended) be more intuitive?
Well, I guess it could go either way. It seems to me that one reason the run() method returns FALSE when there are no validation rules is that the method in fact hasn't validated anything. Comments in the code would seem to support my theory (or wild guess).

PHP Code:
public function run($group '')
{
    
// Do we even have any data to process?  Mm?
    
if (count($_POST) == 0)
    {
        return 
FALSE;
    }

    
// Does the _field_data array containing the validation rules exist?
    // If not, we look to see if they were assigned via a config file
    
if (count($this->_field_data) == 0)
    {
        
// No validation rules?  We're done...
        
if (count($this->_config_rules) == 0)
        {
            return 
FALSE;
        } 

If you have a form you wish to process without any validation rules, you can still use the alternate style of checking for submit and then taking the values from the $_POST array.

PHP Code:
if ($_SERVER['REQUEST_METHOD'] == 'POST'
{
 
   // form was submitted
 
   // process the data, if any
}
else
{
 
   // perhaps redisplay form

Well said man....didn't thought that way Smile