By mummra1 on
In the following code:
$form['priority'] = array(
'#type' => 'radios',
'#title' => t('Requirement Priority'),
'#description' => t('Allows author to prioritize the requirement'),
'#options' => array(t('High'), t('Medium'), t('Low'))
);
...outputs the following html:
<select name="status" class="form-select" id="edit-status" ><option value="0">Incomplete</option><option value="1">Complete</option></select>
This causes major problems when inserting records in to a db, using drupal_write_record, as it is inserting a 0, 1,2, etc in the place of the actual text value of the picklist. Has anyone handled this successfully, to grab the real values from the form?
Thanks
Comments
It is generally best practice
It is generally best practice to explicitly set key values.
This
implies
To explicit set you might use
Note key values should not use the t() function.
nevets, Good idea! I'll
nevets,
Good idea! I'll give it a shot.
interesting
nevets,
This is working in general, except for one of my
elements, even though drupal appears to be outputting the desired markup:
It still inserts 0 and 1 into the 'status' field of the schema...not sure what could be causing this. The other form elements are behaving properly, however.
Do you have that as an
Do you have that as an integer field, possibly a checkbox?
no...the schema
ok, the problem was I had a column in one of my tables called 'status'. This was conflicting with drupals 'Publishing options' area that is default when creating content:
Solution was to change it to 'requirement_status', everything working as planned now.
Thanks for your help...should have known better than to use such a generic name for a column.
Show us your code.
Show us your code.
Contact me to contract me for D7 -> D10/11 migrations.