Re: Quickform2 addDatasource on select group
| From: | Alexey Borzov | Date: | Wed, 06 Oct 2010 21:05:17 +0000 |
| Subject: | Re: Quickform2 addDatasource on select group | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-30752@lists.php.net to get a copy of this message | ||
Hi Cedrick,
On 07.10.2010 0:28, Cedrick Gout wrote:
For some reason when I make a group with a select field in it and want to set the default value for a value from 10-19 it set's it to one, 20-21 sets to two etc. Now we make a group require_once 'HTML/QuickForm2.php'; $form = new HTML_QuickForm2('testSelect'); $form->addDatasource(new HTML_QuickForm2_DataSource_Array(array(First of all, you are passing a wrong value for a group here, should be 'testGroup' => array('test' => 16)'testGroup' => "16" // values 1-9 are selected correctly)));
OUTPUT: <select name="testGroup[test]" id="test-0"> <option value="1" selected="selected">A</option> ...
</select> Does this happen because I'm an idiot or is this a bug?Looks like PHP has pretty strange behaviour concerning string offsets, the following code: $testGroup = "13"; var_dump(isset($testGroup['test']), $testGroup['test']); outputs (without any error messages): bool(true) string(1) "1" It just silently converts 'test' to integer 0 and returns first symbol of the string. So when select element asks Array DataSource for a value of element named 'testGroup[test]' it gets the first symbol of a value for an element named 'testGroup' instead of a more obvious null. Thanks for the report, I think adding an extra is_array() check to Array DataSource may make its behaviour a bit more predictable.