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

  • Home
  • SEARCH
  • 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 8537013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:47:53+00:00 2026-06-11T10:47:53+00:00

I’ve created a new form element class for a special, complex purpose (text input

  • 0

I’ve created a new form element class for a special, complex purpose (text input field with an add-on button to open a “search wizard” popup).

To render this element properly, I’ve also created a form view helper. Everything works and is fine so far.

However, if I try to render the form using the FormCollection view helper, the element is rendered as a basic input element. That’s because the FormElement view helper, which the FormCollection helper relies on, uses a hard-coded series of if clauses to map the element’s type to a specific form view helper. It can’t map my element’s class and thus falls back to FormInput.

I.e. (taken from Zend/Form/View/Helper/FormElement.php, line 41-49):

    if ($element instanceof Element\Button) {
        $helper = $renderer->plugin('form_button');
        return $helper($element);
    }

    if ($element instanceof Element\Captcha) {
        $helper = $renderer->plugin('form_captcha');
        return $helper($element);
    }

    ...

    $helper = $renderer->plugin('form_input');
    return $helper($element);

and so on.

I’ve got a little stuck here because this architecture doesn’t really promote extensibility.

The only solution that came to my mind (except rendering the form by hand) is to extend the FormElement view helper class and thus create my own CustomFormElement view helper. However, because of its complexity, I’ve put the custom element into an own module. So I’d have to write this CustomFormElement helper dynamically to add custom elements from any module. I don’t think this is a recommended procedure.

Is there another solution or is maybe even my complete approach unrecommended? Thanks in advance!

  • 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-06-11T10:47:54+00:00Added an answer on June 11, 2026 at 10:47 am

    Seems like we’re both running into Form issues with Zend. I think that it could be better integrated with the whole MVC structure.

    I think that your approach is sound. What I might think of doing is the following

    1. Give your elements a variable named helper like in ZF1.
    2. Create the custom form element renderer that will ALSO check the renderer attribute of a form element to decide on how to render it.

    You could re-use the ViewHelperProviderInterface or create your own interface:

    class CustomElement implements ViewHelperProviderInterface
    {
         public function getViewHelperConfig()
         {
              return array('type' => '\My\View\Helper');
         }
    }
    

    or

    class CustomElement implements FormHelperProviderInterface
    {
         public function getFormHelperConfig()
         {
              return '\My\View\Helper';
              // or
              return new My\View\Helper();
         }
    }
    

    Then in your FormElement class you can do the following:

        if ('week' == $type) {
            $helper = $renderer->plugin('form_week');
            return $helper($element);
        }
    
        if ($element instanceof THEINTERFACE) {
              return $renderer->plugin($element->getFormHelperConfig());
        }
    
        $helper = $renderer->plugin('form_input');
        return $helper($element);
    

    This is probably what you had in mind anyway.

    You’d probably be better off creating your own interface since the first one already has some sort of meaning behind it and it might confuse someone.

    Aside from that, each module would then ONLY have to provide a helper_map key in the module configuration to have it’s view helpers available during rendering with the MVC components.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT

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.