Issue 204 in php-form-builder-class: Multiple Select - Multiple values not showing as pre-selected

28 views
Skip to first unread message

php-form-bu...@googlecode.com

unread,
Aug 13, 2013, 7:54:03 AM8/13/13
to php-form-builder...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 204 by docon...@gmail.com: Multiple Select - Multiple values not
showing as pre-selected
http://code.google.com/p/php-form-builder-class/issues/detail?id=204

What steps will reproduce the problem?
1.
$form->addElement(new PFBC\Element\Select("Test:", "test[]",
array('1'=>'one','2'=>'two','3'=>'three'),
array('value'=>array(1,2),
'multiple'=>'true'
)));


What is the expected output?

A multi select box with 3 values, where 2 are pre-selected

What do you see instead?

A multi-select box with 3 values, where only 1 is pre-selected

What version of the product are you using? On what operating system?

Version 3.1
PHP 5.3+

Please provide any additional information below.

The problem appears to be in the file:


https://code.google.com/p/php-form-builder-class/source/browse/trunk/PFBC/Element/Select.php

Lines 23-26

Once select is set the first time, the IF test fails for all future
values even if in_array(..) is true.

Commenting out the set value on line 25 is a hack solution that fixes
the issue.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

php-form-bu...@googlecode.com

unread,
May 4, 2015, 2:09:39 AM5/4/15
to php-form-builder...@googlegroups.com

Comment #1 on issue 204 by jamil.ab...@qualizone-lb.com: Multiple Select -
Multiple values not showing as pre-selected
https://code.google.com/p/php-form-builder-class/issues/detail?id=204

Hi
I replaced my render file with the following to make it work:

public function render() {
if(isset($this->_attributes["value"])) {
if(!is_array($this->_attributes["value"]))
$this->_attributes["value"] = array($this->_attributes["value"]);
}
else
$this->_attributes["value"] = array();

if( isset($this->_attributes["multiple"]) &&
$this->_attributes["multiple"] == true)
{
$multiple=true;
}
if($multiple && substr($this->_attributes["name"], -2) != "[]")
$this->_attributes["name"] .= "[]";

echo '<select', $this->getAttributes(array("value", "selected")), '>';
$selected = false;
foreach($this->options as $value => $text) {
$value = $this->getOptionValue($value);
echo '<option value="', $this->filter($value), '"';
if((!$selected || $multiple) && in_array($value,
$this->_attributes["value"])) {
echo ' selected="selected"';
$selected = true;
}
echo '>', $text, '</option>';
}
echo '</select>';
Reply all
Reply to author
Forward
0 new messages