Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7493239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:50:12+00:00 2026-05-29T16:50:12+00:00

I’m trying to set the prefix path for Zend Form’s validators and filters automatically.

  • 0

I’m trying to set the prefix path for Zend Form’s validators and filters automatically. I’ve done a lot of research and found many solutions, but I want these to always take effect, automatically. I know I can do this in the form:

$this->addElementPrefixPath('My_Validate', 'My/Validate/', 'validate');

or set them on an element such as

$input->addValidatorPrefixPath('Other_Namespace', 'Other/Namespace');
$input->addFilterPrefixPath('Foo_Namespace', 'Foo/Namespace');

but is there any way for these to automatically look into what’s already set in the autoloader and/or be set in the bootstrap (or elsewhere), without having to set it ever again?

Here’s my autoloader:

// Autoload libraries
$autoloader = Zend_Loader_Autoloader::getInstance();    
$autoloader->registerNamespace('Lib1_')
   ->registerNamespace('Lib2_')
   ->registerNamespace('Lib3_');

Now, when I add a validator using

->addValidator('CustomValidator', false, 1)

I would like it to respect the hierarchy listed in the autoloader, falling back to Zend after that. I just haven’t been able to find how to automatically bootstrap this kind of autoloading for the validators and filters.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:50:15+00:00Added an answer on May 29, 2026 at 4:50 pm

    The way I get settings like this into all of my Zend forms without having to repeat the code all over for each form is to create a base form class that extends Zend_Form, which in turn all of my other forms extend.

    In the base form’s constructor, I set up different decorators for various types of elements or customize the decorators for my application, specify prefix paths for helpers and validators and other things.

    The important thing to note about this method, is you must call parent::__construct() as the very last line if your base form __construct method. The reason for this is because the Zend_Form::init() method gets called by Zend_Form::__construct() and nothing else from the constructor runs after that.

    Here is an example:

    <?php
    
    class Application_Form_Base extends Zend_Form
    {
        // decorator spec for form elements like text, select etc.
        public $elementDecorators = array(
            'ViewHelper',
            'Errors',
            array('Description', array('tag' => 'p', 'class' => 'description', 'escape' => false)),
            array('HtmlTag', array('class' => 'form-div')),
            array('Label', array('class' => 'form-label', 'requiredSuffix' => '*'))
        );
    
        // decorator spec for checkboxes
        public $checkboxDecorators = array(
            'ViewHelper',
            'Errors',
            array('Label', array('class' => 'form-label', 'style' => 'display: inline', 'requiredSuffix' => '*', 'placement' => 'APPEND')),
            array('HtmlTag', array('class' => 'form-div')),
            array('Description', array('tag' => 'p', 'class' => 'description', 'escape' => false, 'placement' => 'APPEND')),
        );
    
        // decorator spec for submits and buttons
        public $buttonDecorators = array(
            'ViewHelper',
            array('HtmlTag', array('tag' => 'div', 'class' => 'form-button'))
        );
    
        public function __construct()
        {
            // set the <form> decorators
            $this->setDecorators(array(
                                 'FormElements',
                                 array('HtmlTag', array('tag' => 'div', 'class' => 'form')),
                                 'Form'));
    
            // set this as the default decorator for all elements added to the form
            $this->setElementDecorators($this->elementDecorators, array('submit', 'button'), true);
    
            // add prefix paths for decorators and validators
            $this->addElementPrefixPath('My_Decorator', 'My/Decorator', 'decorator');
            $this->addElementPrefixPath('My_Validator', 'My/Validator', 'validate');
    
            parent::__construct();
            // parent::__construct must be called last because it calls $form->init()
            // and anything after it is not executed
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.