• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form_validation run() method

#1
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?
Reply

#2
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

Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply

#3
Well said man....didn't thought that way Smile
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.