Zend Framework

Zend_Form_Element_Select addMultiOption method fails to render labels/options containing £

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Cannot Reproduce
  • Affects Version/s: 1.8.4, 1.9.4, 1.9.5
  • Fix Version/s: 1.9.6
  • Component/s: Zend_Form
  • Labels:
    None

Description

I have some multioptions (which are monetary values), If I add elements like so:

$prices = array([0]=>'20000'........etc

foreach ($prices as $price) { $minprice->addMultiOption($price,'£'.number_format($price)); }

The select box comes out with the correct amount of options, with the values set, but nothing between the <option> tags and nothing on the label attribute.

Activity

Hide
Steve Hollis added a comment -

Please supply code to reproduce.

Ignoring the encoding issue, the following code:

$minprice = new Zend_Form_Element_Select('minprice');
$prices = array(0 => '20000');
foreach ($prices as $price) {
    $minprice->addMultiOption($price,'£'.number_format($price));
}
$minprice->setView(new Zend_View());
echo $minprice->render();

...produces:

<dt id="minprice-label">&nbsp;</dt>
<dd id="minprice-element">
<select name="minprice" id="minprice">
    <option value="20000" label="£20,000">£20,000</option>
</select></dd>
Show
Steve Hollis added a comment - Please supply code to reproduce. Ignoring the encoding issue, the following code:
$minprice = new Zend_Form_Element_Select('minprice');
$prices = array(0 => '20000');
foreach ($prices as $price) {
    $minprice->addMultiOption($price,'£'.number_format($price));
}
$minprice->setView(new Zend_View());
echo $minprice->render();
...produces:
<dt id="minprice-label">&nbsp;</dt>
<dd id="minprice-element">
<select name="minprice" id="minprice">
    <option value="20000" label="£20,000">£20,000</option>
</select></dd>
Hide
Nick Pack added a comment -

Form extends Zend_Form in the usual manner (as per the quickstart)

In the init() method:

$minprice = $this->createElement('select','MinPrice');
		$minprice->setLabel('Minimum Price')
				 ->addMultiOption('0','No Preference');
		$maxprice = $this->createElement('select','MaxPrice');
		$maxprice->setLabel('Maximum Price')
				 ->addMultiOption('0','No Preference');
		foreach ($this->_settings['pricerange'] as $price) {
			$minprice->addMultiOption($price,'£'.number_format($price));
			$maxprice->addMultiOption($price,'£'.number_format($price));
		}

Which produces:

<dt id="MinPrice-label"><label for="MinPrice" class="optional">Minimum Price</label></dt>
<dd id="MinPrice-element">
<select name="MinPrice" id="MinPrice">
    <option value="0" label="No Preference">No Preference</option>
    <option value="50000" label=""></option>
    <option value="100000" label=""></option>
    <option value="125000" label=""></option>
    <option value="150000" label=""></option>
    <option value="175000" label=""></option>

    <option value="200000" label=""></option>
    <option value="250000" label=""></option>
    <option value="300000" label=""></option>
    <option value="400000" label=""></option>
    <option value="500000" label=""></option>
    <option value="750000" label=""></option>
    <option value="1000000" label=""></option>
    <option value="2000000" label=""></option>
    <option value="5000000" label=""></option>

</select></dd>
<dt id="MaxPrice-label"><label for="MaxPrice" class="optional">Maximum Price</label></dt>
<dd id="MaxPrice-element">
<select name="MaxPrice" id="MaxPrice">
    <option value="0" label="No Preference">No Preference</option>
    <option value="50000" label=""></option>
    <option value="100000" label=""></option>
    <option value="125000" label=""></option>
    <option value="150000" label=""></option>
    <option value="175000" label=""></option>

    <option value="200000" label=""></option>
    <option value="250000" label=""></option>
    <option value="300000" label=""></option>
    <option value="400000" label=""></option>
    <option value="500000" label=""></option>
    <option value="750000" label=""></option>
    <option value="1000000" label=""></option>
    <option value="2000000" label=""></option>
    <option value="5000000" label=""></option>

</select></dd>

$this->_settings['pricerange'] array is set from application.ini via a bootstrap method, storing them in the registry.

View is set as follows (incase that helps):

$view->setEncoding('UTF-8');
$view->doctype('XHTML11');

Simply omitting the £ the option label etc are set correctly.

Show
Nick Pack added a comment - Form extends Zend_Form in the usual manner (as per the quickstart) In the init() method:
$minprice = $this->createElement('select','MinPrice');
		$minprice->setLabel('Minimum Price')
				 ->addMultiOption('0','No Preference');
		$maxprice = $this->createElement('select','MaxPrice');
		$maxprice->setLabel('Maximum Price')
				 ->addMultiOption('0','No Preference');
		foreach ($this->_settings['pricerange'] as $price) {
			$minprice->addMultiOption($price,'£'.number_format($price));
			$maxprice->addMultiOption($price,'£'.number_format($price));
		}
Which produces:
<dt id="MinPrice-label"><label for="MinPrice" class="optional">Minimum Price</label></dt>
<dd id="MinPrice-element">
<select name="MinPrice" id="MinPrice">
    <option value="0" label="No Preference">No Preference</option>
    <option value="50000" label=""></option>
    <option value="100000" label=""></option>
    <option value="125000" label=""></option>
    <option value="150000" label=""></option>
    <option value="175000" label=""></option>

    <option value="200000" label=""></option>
    <option value="250000" label=""></option>
    <option value="300000" label=""></option>
    <option value="400000" label=""></option>
    <option value="500000" label=""></option>
    <option value="750000" label=""></option>
    <option value="1000000" label=""></option>
    <option value="2000000" label=""></option>
    <option value="5000000" label=""></option>

</select></dd>
<dt id="MaxPrice-label"><label for="MaxPrice" class="optional">Maximum Price</label></dt>
<dd id="MaxPrice-element">
<select name="MaxPrice" id="MaxPrice">
    <option value="0" label="No Preference">No Preference</option>
    <option value="50000" label=""></option>
    <option value="100000" label=""></option>
    <option value="125000" label=""></option>
    <option value="150000" label=""></option>
    <option value="175000" label=""></option>

    <option value="200000" label=""></option>
    <option value="250000" label=""></option>
    <option value="300000" label=""></option>
    <option value="400000" label=""></option>
    <option value="500000" label=""></option>
    <option value="750000" label=""></option>
    <option value="1000000" label=""></option>
    <option value="2000000" label=""></option>
    <option value="5000000" label=""></option>

</select></dd>
$this->_settings['pricerange'] array is set from application.ini via a bootstrap method, storing them in the registry. View is set as follows (incase that helps):
$view->setEncoding('UTF-8');
$view->doctype('XHTML11');
Simply omitting the £ the option label etc are set correctly.
Hide
Matthew Weier O'Phinney added a comment -

I've added a test case for this, and, quite simply, am unable to reproduce the issue. Most likely, it's a problem related to encoding of the script and/or your web server.

Show
Matthew Weier O'Phinney added a comment - I've added a test case for this, and, quite simply, am unable to reproduce the issue. Most likely, it's a problem related to encoding of the script and/or your web server.
Hide
Nick Pack added a comment -

As per your suggestion about encoding, removing $view->setEncoding('UTF-8'); from my bootstrap gets this a step further, but results in:

<select name="MinPrice" id="MinPrice">
    <option value="0" label="No Preference" selected="selected">No Preference</option>
    <option value="50000" label="�50,000">�50,000</option>

    <option value="100000" label="�100,000">�100,000</option>
    <option value="125000" label="�125,000">�125,000</option>
    <option value="150000" label="�150,000">�150,000</option>
    <option value="175000" label="�175,000">�175,000</option>
    <option value="200000" label="�200,000">�200,000</option>
    <option value="250000" label="�250,000">�250,000</option>

    <option value="300000" label="�300,000">�300,000</option>
    <option value="400000" label="�400,000">�400,000</option>
    <option value="500000" label="�500,000">�500,000</option>
    <option value="750000" label="�750,000">�750,000</option>
    <option value="1000000" label="�1,000,000">�1,000,000</option>
    <option value="2000000" label="�2,000,000">�2,000,000</option>

    <option value="5000000" label="�5,000,000">�5,000,000</option>
</select>

View is set up as follows:

protected function _initDoctype()
    {
    	$this->bootstrap('view');
        $view = $this->getResource('view');
        $view->setEncoding('UTF-8');
        $view->doctype('XHTML11'); 	
    }

The app follows almost to a T the quick start (in terms of structure, the default layout etc), can you give me any pointers in order to get this resolved?

Thanks

Show
Nick Pack added a comment - As per your suggestion about encoding, removing $view->setEncoding('UTF-8'); from my bootstrap gets this a step further, but results in:
<select name="MinPrice" id="MinPrice">
    <option value="0" label="No Preference" selected="selected">No Preference</option>
    <option value="50000" label="�50,000">�50,000</option>

    <option value="100000" label="�100,000">�100,000</option>
    <option value="125000" label="�125,000">�125,000</option>
    <option value="150000" label="�150,000">�150,000</option>
    <option value="175000" label="�175,000">�175,000</option>
    <option value="200000" label="�200,000">�200,000</option>
    <option value="250000" label="�250,000">�250,000</option>

    <option value="300000" label="�300,000">�300,000</option>
    <option value="400000" label="�400,000">�400,000</option>
    <option value="500000" label="�500,000">�500,000</option>
    <option value="750000" label="�750,000">�750,000</option>
    <option value="1000000" label="�1,000,000">�1,000,000</option>
    <option value="2000000" label="�2,000,000">�2,000,000</option>

    <option value="5000000" label="�5,000,000">�5,000,000</option>
</select>
View is set up as follows:
protected function _initDoctype()
    {
    	$this->bootstrap('view');
        $view = $this->getResource('view');
        $view->setEncoding('UTF-8');
        $view->doctype('XHTML11'); 	
    }
The app follows almost to a T the quick start (in terms of structure, the default layout etc), can you give me any pointers in order to get this resolved? Thanks
Hide
Nick Pack added a comment -

Just incase someone else comes across this, I found the cause of the problem outlined above, which as rightly said by Matthew Weier O'Phinney isnt a bug in ZF after all...

The issue is caused by Zend Studio For Eclipse, when run on a mac it defaults to using a mac-roman character set, this is the sole reason seemingly valid code was producing this problem, converting the scripts in question to UTF-8 corrects this problem

Show
Nick Pack added a comment - Just incase someone else comes across this, I found the cause of the problem outlined above, which as rightly said by Matthew Weier O'Phinney isnt a bug in ZF after all... The issue is caused by Zend Studio For Eclipse, when run on a mac it defaults to using a mac-roman character set, this is the sole reason seemingly valid code was producing this problem, converting the scripts in question to UTF-8 corrects this problem

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: