First of all, sorry for posting before in a quite old post (https://drupal.org/node/240783). This new post is related to mentioned one.
I have next field in a form
form['aform']['status'] = array('#type' => 'select',
'#title' => t('Status'),
'#options' => array(0 => 'OFF', 1 => 'ON'),
'#value' => $previousIfExisted,
'#required' => TRUE);
The question is that this form is same used to add new records in a db table as for editing existing ones. So If editing, the previously selected value for this
filed should be shown. And so $previousIfExisted will be 0 by default and whichever the previuosly selected.
No way men, I cannot get it working.
Some one said (in older versions of drupal in the above mentioned post) that the options array should be of type
array('OFF'=>'OFF', 'ON'=>'ON');
Where keys and values are the same. :| Actually thrilling if someone's got keys like 'this is my option one'.
Some one knows what am i doing wrong ?
Comments
You don't have to make the
You don't have to make the keys of the array the same as the values, you just have to know that the key will be the value that is submitted.
Anyways, you didn't show how you set $previousIfExisted, so we can't really say why its not working.
Contact me to contract me for D7 -> D10/11 migrations.
Ok, some more comprehensive
Ok, some more comprehensive info:
And the select field aaaaalways show the default value (first value)
Let's close a post which
Let's close a post which never should have existed...
where code above said
it should say
Just a mistake done by bad programmer .... nothing of interest for other drupal developers.
Good night.
What do you get if you add
What do you get if you add this:
die('<pre>' . print_r($status, true) . '</pre>');after
$status = $thecam[$cid]['status'];Contact me to contract me for D7 -> D10/11 migrations.
The expected value
Never mind man, see my above post, it's solved, I simply forgot I was working with an array of arrays .... that was all ..... my fault
Thanks for help.