PHP Classes

How to Call Class Method for ValidationServerFunction

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  How to Call Class Method for...  >  (Un) Subscribe thread alerts  
Subject:How to Call Class Method for...
Summary:How to Call Class Method for ValidationServerFunction
Messages:6
Author:Larry Pack
Date:2012-04-20 08:05:11
Update:2012-04-22 06:19:49
 

  1. How to Call Class Method for...   Reply   Report abuse  
Picture of Larry Pack Larry Pack - 2012-04-20 08:05:11
Hi. How do I call a method from another class for the ValidationServerFunction? The standard way in php to call a callback function is array( $class_object, 'class_method' ). But this doesn't work. Nor does "$class_object->class_method". Not sure what to do here. Any help would be greatly appreciated.

  2. Re: How to Call Class Method for...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-04-20 08:21:37 - In reply to message 1 from Larry Pack
You may try calling a static function of that class.

If that would not do, maybe you can create a plug-in class that implements that kind of validation you want. That can handle both server and browser side validation if you need that too. Take a look at the test_custom_validation.php example script.

  3. Re: How to Call Class Method for...   Reply   Report abuse  
Picture of Larry Pack Larry Pack - 2012-04-20 08:27:45 - In reply to message 2 from Manuel Lemos
Thanks for the reply. How would I call the static function? Would it be like this:
"ValidationServerFunction"=>"Class::static_method"

  4. Re: How to Call Class Method for...   Reply   Report abuse  
Picture of Larry Pack Larry Pack - 2012-04-20 08:44:21 - In reply to message 3 from Larry Pack
Hi again. Calling a static method doesn't work. However, if you modify line 3396 of forms.php to read
if(!call_user_func($input["ValidationServerFunction"], $value))
you can then call static functions.

  5. Re: How to Call Class Method for...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-04-21 21:00:56 - In reply to message 4 from Larry Pack
Yes, you are right. I made the class use call_user_func instead, so it works with classes static functions, object class functions, or even closures. It will be made available in the next release. Thank you for the suggestion.

  6. Re: How to Call Class Method for...   Reply   Report abuse  
Picture of Larry Pack Larry Pack - 2012-04-22 06:19:49 - In reply to message 5 from Manuel Lemos
Awesome. Looking forward to the next release!