[Solar-talk] adding filter validate class
Antti Holvikari
anttih at gmail.com
Thu Mar 6 08:22:25 CST 2008
On Thu, Mar 6, 2008 at 3:48 PM, Jeff Surgeson <solar at 3hex.com> wrote:
> Hi All
>
> I know that a similar question was asked in previous months but I cant make it
> work as my useage is slightly differant.
>
> I am trying to add a filter method to validate form user input, I also wanted
> to set it up so I could add other validation and sanitize methods unique to
> my use, this is what I have done.
>
> class Vendor_Filter extends Solar_Filter{}
>
> class Vendor_Filter_ValidateMethod extends Solar_Filter_Abstract {
> public function validateMethod(){
> // validate code
> }
> }
>
> In my application class I have a method to create a form which calls the
> validate method
>
> public function contactForm()
> {
> $form = Solar::factory('Solar_Form');
> $form->setElements(array(
> 'telno' => array(
> 'filters' => array(
> 'validateMethod',
> ),
> .....
> .....
> }
>
> I tried adding protected $_filter_class = 'Vendor_Filter'; to my application
> class.
>
> It generates an exception as class not found, I assume as it is only searching
> Solar_Filter and not Vendor_Filter. It would appear from what Paul and Anttih
> say that it is possible when used in a Model class
>
> Am I on the right track doing it as above and if so what am I missing?
In this situation you need to inject Solar_Form with the correct
filter instance. For that filter instance you need to tell where to
look for filters.
So
$filter = Solar::factory('Solar_Filter');
$filter->addFilterClass('Vendor_Filter');
$form = Solar::factory('Solar_Form', array('filter' => $filter));
// ...
Hope that helps.
--
Antti Holvikari <http://anttih.com>
More information about the Solar-talk
mailing list