In Drupal 6, by default, a required CCK field will display the first allowed value.
I want it displays "- Please Select -": Is there an easy way to do this?
I do not want to save "- Please Select -" in the database.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityIn Drupal 6, by default, a required CCK field will display the first allowed value.
I want it displays "- Please Select -": Is there an easy way to do this?
I do not want to save "- Please Select -" in the database.
Use the key|label format for allowed values:
|-Please Select -
1|option1
2|option2
3|option3
By making the key for "-Please Select -" an empty string, the form can't be submitted with this value.
In the list of options of global settings of field you can put in first place the option - Please Select - :
-Please Select -
option1
option2
option3
Save the field.
After in the field settings you choose - Please Select - in default value of the field.
Finally you save the configuration of field.
Put your field as not required and then in a hook_nodeapi()
check that the user has effectively selected a value:
function custom_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'validate') {
if ($node->field_select[0]['value'] == '') {
form_set_error('field_select', t('Please select a value.'));
}
}
}
seems like AHAH can do the job to populate select list or add items: AHAH - populating a select (list) with a select (drop-down).