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 6390325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:30:47+00:00 2026-05-25T03:30:47+00:00

Hello i am using Zend Framework Form and have tried to get this example

  • 0

Hello i am using Zend Framework Form and have tried to get this example to work http://framework.zend.com/issues/browse/ZF-8252, but it fails xD

this is my code

$options = Array
(
    [] => Qualsiasi Agente
    [agenti_attivi] => Array
        (
            [4] => Giovanni Abc
            [10] => Luigi Abc
            [13] => Michela Abc
        )

);

$agenti->addMultiOptions($options);

and the generated code is :

<select name="agente_id" id="agente_id" tabindex="6">
    <option value="" label="Qualsiasi Agente" selected="selected">Qualsiasi Agente</option>
    <optgroup id="agente_id-optgroup-Agenti attivi: " label="Agenti attivi: ">
    <option value="4" label="Giovanni Abc">Giovanni Abc</option>
    <option value="10" label="Luigi Capoarea">Luigi Abc</option>
    <option value="13" label="Michela Abc">Michela Abc</option>
    </optgroup>

</select>

where id=”agente_id-optgroup-Agenti attivi: “ is not xhtml valid Line 724, Column 44: value of attribute “id” must be a single token

i am using zend 1.11.10

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-25T03:30:47+00:00Added an answer on May 25, 2026 at 3:30 am

    Create a custom view helper FormSelect that extends the core FormSelect and then modify the code.

    1. Include the path to your view helpers in the bootstrap file

    protected function _initHelpers()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->addHelperPath('My/View/Helper', 'My_View_Helper');
    }
    
    1. The custom view helper. It’s a copy of Zend_View_Helper_FormSelect but with small modification.

      class My_View_Helper_FormSelect extends Zend_View_Helper_FormSelect
      {

      public function formSelect($name, $value = null, $attribs = null,
          $options = null, $listsep = "<br />\n")
      {
          $info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
          extract($info); // name, id, value, attribs, options, listsep, disable
      
          // force $value to array so we can compare multiple values to multiple
          // options; also ensure it's a string for comparison purposes.
          $value = array_map('strval', (array) $value);
      
          // check if element may have multiple values
          $multiple = '';
      
          if (substr($name, -2) == '[]') {
              // multiple implied by the name
              $multiple = ' multiple="multiple"';
          }
      
          if (isset($attribs['multiple'])) {
              // Attribute set
              if ($attribs['multiple']) {
                  // True attribute; set multiple attribute
                  $multiple = ' multiple="multiple"';
      
                  // Make sure name indicates multiple values are allowed
                  if (!empty($multiple) && (substr($name, -2) != '[]')) {
                      $name .= '[]';
                  }
              } else {
                  // False attribute; ensure attribute not set
                  $multiple = '';
              }
              unset($attribs['multiple']);
          }
      
          // now start building the XHTML.
          $disabled = '';
          if (true === $disable) {
              $disabled = ' disabled="disabled"';
          }
      
          // Build the surrounding select element first.
          $xhtml = '<select'
                  . ' name="' . $this->view->escape($name) . '"'
                  . ' id="' . $this->view->escape($id) . '"'
                  . $multiple
                  . $disabled
                  . $this->_htmlAttribs($attribs)
                  . ">\n    ";
      
          // build the list of options
          $list       = array();
          $translator = $this->getTranslator();
          foreach ((array) $options as $opt_value => $opt_label) {
              if (is_array($opt_label)) {
                  $opt_disable = '';
                  if (is_array($disable) && in_array($opt_value, $disable)) {
                      $opt_disable = ' disabled="disabled"';
                  }
                  if (null !== $translator) {
                      $opt_value = $translator->translate($opt_value);
                  }
                  $opt_id = ' id="' . $this->formatElementId($id . '-optgroup-' . $opt_value) . '"';
                  $list[] = '<optgroup'
                          . $opt_disable
                          . $opt_id
                          . ' label="' . $this->view->escape($opt_value) .'">';
                  foreach ($opt_label as $val => $lab) {
                      $list[] = $this->_build($val, $lab, $value, $disable);
                  }
                  $list[] = '</optgroup>';
              } else {
                  $list[] = $this->_build($opt_value, $opt_label, $value, $disable);
              }
          }
      
          // add the options to the xhtml and close the select
          $xhtml .= implode("\n    ", $list) . "\n</select>";
      
          return $xhtml;
      }
      
      private function formatElementId($id)
      {
          // in here put whatever filter you want for the id value
          $id = trim(strtr($id, array('[' => '-', ']' => '', ' ' => '', ':' => '')), '-');
          $id = strtolower($id);
          return $id;
      }
      

      }

    Done. Create multi select element with a valid id.

    <?php
    $this->addElement('multiSelect', 'agente_id', array(
        'label' => 'Label Name:',
        'multiOptions' => array(
            '' => 'Qualsiasi Agente',
            'Agenti attivi: ' => array(
                4 => 'Giovanni Verdi',
                10 => 'Luigi Capoarea',
                13 => 'Michela Passarin',
            )
        )
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i'm using this example http://lexandera.com/2009/01/extracting-html-from-a-webview/ to get the HTML from a webview. But
hello all its my first application using Zend Framework i have followed tutorial it
I finished some of the steps in http://framework.zend.com/manual/en/learning.quickstart.create-project.html and got it to work to
hello im using this code to do search <form action=arama.php method=get> <input type=text name=lol>
I am using Zend Framework v 1.10 I have created a custom function in
I have finally got a zend view helper working using this in my helper
I am new to zend framework. I have used zend form and decorators to
hello I am using zend framework and i am trying to combine it with
I have a class: class MyClass(object): @property def myproperty(self): return 'hello' Using mox and
Hello i am using NSOperationQueue to download images in the background. I have created

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.