Login Retreive lost passwordRegister
Search

Forum Index / Feedback / methods as validator

[ This topic is solved ]

  Tsan-Kuang Lee 12 July 05 / 23:09  
Great product!

While one can use methods (in classes) for onCorrect, validators are restricted to functions. Can this restriction be loosened in the next version?

Thanks a lot!

  Tsan-Kuang Lee 13 July 05 / 00:04  
Changed at 13 July 05 / 15:37
I couldn't wait so I went ahead and patched a little bit. Hope this helps. By the way, "call_user_func" is used instead of "call_user_method" which is deprecated.

Filename: fields/class.Field.php


<?php
    
function isValid() {
        
        
// is a validator set?
        
if(isset($this->_sValidator) && $this->_sValidator != null) {
            
// if it's an array, it's a method
            
if (!is_array($this->_sValidator)) {
                
// is the validator a user-spicified function?
                
if( function_exists($this->_sValidator) ) {
                    
$error call_user_func$this->_sValidator$this->getValue() );
                } else {
                    
$v =& new Validator();
                    if(
method_exists($v$this->_sValidator)) {
                        
// call the build in  validator function
                        
$error $v->{$this->_sValidator}( $this->getValue() );
                        
                    } else {
                        
trigger_error("Unknown validator: '".$this->_sValidator."' used in field '".$this->_sName."'");
                        
$error false;
                    }
                }
               } else {
                
// check if the method exists
                
if(method_exists($this->_sValidator[0], $this->_sValidator[1])) {
                    
$error call_user_func(array($this->_sValidator[0], $this->_sValidator[1]), $this->getValue());
                } else {
                    
trigger_error(
                      
"Error, the validator method '".$this->_sValidator[1]."' does not exists ".
                      
"in object '".get_class($this->_sValidator[0])."'!",
                      
E_USER_ERROR);
                    
$error false;
                }
            }

            
// set the error message
            
$this->_sError 
              
is_string($error) ? $error :
              (!
$error $this->_oForm->_text14 ) :
              (isset(
$this->_sError) ? $this->_sError ''));        
        }                

        
        return empty( 
$this->_sError );
    }
?>


  Mels van Kooten 13 July 05 / 11:16  
Changed at 13 July 05 / 11:16
Hi Tsan-Kuang Lee,
Thanx for the tip en modification!

For us Dutch people almost all the validations are included, so I never thought about this.
But I think it's a great add-on.

I'll leave it up to Teye to put this in or not, but I think he will.

  Teye Heimans (Founder) 13 July 05 / 12:12  
I've updated the file. Thanks for the tip and code!

  Tsan-Kuang Lee 13 July 05 / 15:27  
Changed at 13 July 05 / 15:38
I apologize that I had a typo and missed a line in the original post (I've already fixed both in the post above) -- I had a "$$" in line 103 and I missed $error = false in line 107.

For your information, a typical user validator application would be "check in the database to find duplications (e.g. user name)".

  Teye Heimans (Founder) 13 July 05 / 16:46  
 Quote: Tsan-Kuang Lee
 
I apologize that I had a typo and missed a line in the original post (I've already fixed both in the post above) -- I had a "$$" in line 103 and I missed $error = false in line 107.

For your information, a typical user validator application would be "check in the database to find duplications (e.g. user name)".


Np, I had allready changed these faults so the code in the download is OK. Can I ask where your from?

  Tsan-Kuang Lee 13 July 05 / 17:35  
 Quote: Teye Heimans
 
[...]

Np, I had allready changed these faults so the code in the download is OK. Can I ask where your from?


Thanks a lot for the product again. I'm from Taiwan.

  Teye Heimans (Founder) 13 July 05 / 17:38  
Could you translate a language file for me so that I can add it to the package?

  Tsan-Kuang Lee 13 July 05 / 17:47  
Sure. No problem.

I will give you two files for both Traditional and Simplified Chinese. Typically, they have different encoding schemes (BIG5 and GB2312) but I think I'll just use UTF-8.

Since your forum system doesn't use UTF-8, please give me your email address (you can find my email in your registration records) so I can send you the files.

  Top


powered by PHP-GLOBE   © 2004 - 2012 FormHandler. All rights reserved.   -   Open source license