By nimzie on
HI, I have a field ( field_unit_price ) which I can hide with my little module here ( with unset ). That's fine.
In certain cases ( when there is a query string after the args - i.e. ?something=something&other=somethingelse ), I want to disable the field.
2 questions
In form_alter, how do I disable this field?
I've tried
$form['field_unit_price'][#disabled]=TRUE and $form['field_unit_price'][value][0][#disabled]=TRUE
and neither work.
Question #2 - How do I ask Drupal if there is a ?something ..... in the URL after the Args? Forgive my improper terminology ..
Thanks for your help.
Cheers,
Adam
Comments
For question 1, #disabled
For question 1,
#disabledshould be'#disabled'(notice the single quotes)For question two you want to use arg(), given the path "node/123", arg(0) would return 'node' and arg(1) would return '123'.
disable using method 1
does $form['field_unit_price']['#disabled']=TRUE work though ? i tried to disable a field f1 using
and it did not disable it :(.
thx.
yashesh bhatia.
Yashesh Bhatia
print_r($form)
first of all you have to see the strusture of $form array
echo "
"; print_r($form); exit; then add new attributes ['#disabled'] = TRUE into specific field http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6Pragna J Bhalsod
thx for the info. thats done
thx for the info. thats done long before.. check out the logger statement which sees the fields of $form. now if u have a field - f1. it'll create an array element - field_f1 .
as per the conversation above we tried it on the field. do u have a working snippet for it ?.
yashesh bhatia
Yashesh Bhatia
cck export dump..
also.. here's the cck export dump. u can easily import it and then provide a snippet for the field to be turned disabled.
$content['type'] = array (
'name' => 'yvb1',
'type' => 'yvb1',
'description' => '',
'title_label' => 'Title',
'body_label' => '',
'min_word_count' => '0',
'help' => '',
'node_options' =>
array (
'status' => true,
'promote' => true,
'sticky' => false,
'revision' => false,
),
'old_type' => 'yvb1',
'orig_type' => '',
'module' => 'node',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'comment' => '2',
'comment_default_mode' => '4',
'comment_default_order' => '1',
'comment_default_per_page' => '50',
'comment_controls' => '3',
'comment_anonymous' => 0,
'comment_subject_field' => '1',
'comment_preview' => '1',
'comment_form_location' => '0',
);
$content['fields'] = array (
0 =>
array (
'label' => 'f1',
'field_name' => 'field_f1',
'type' => 'text',
'widget_type' => 'text_textfield',
'change' => 'Change basic information',
'weight' => '31',
'rows' => 5,
'size' => '60',
'description' => '',
'default_value' =>
array (
0 =>
array (
'value' => '',
'_error_element' => 'default_value_widget][field_f1][0][value',
),
),
'default_value_php' => '',
'default_value_widget' => NULL,
'group' => false,
'required' => 0,
'multiple' => '0',
'text_processing' => '0',
'max_length' => '',
'allowed_values' => '',
'allowed_values_php' => '',
'op' => 'Save field settings',
'module' => 'text',
'widget_module' => 'text',
'columns' =>
array (
'value' =>
array (
'type' => 'text',
'size' => 'big',
'not null' => false,
'sortable' => true,
'views' => true,
),
),
'display_settings' =>
array (
'label' =>
array (
'format' => 'above',
'exclude' => 0,
),
'teaser' =>
array (
'format' => 'default',
'exclude' => 0,
),
'full' =>
array (
'format' => 'default',
'exclude' => 0,
),
4 =>
array (
'format' => 'default',
'exclude' => 0,
),
),
),
1 =>
array (
'label' => 'f2',
'field_name' => 'field_f2',
'type' => 'text',
'widget_type' => 'text_textfield',
'change' => 'Change basic information',
'weight' => '32',
'rows' => 5,
'size' => '60',
'description' => '',
'default_value' =>
array (
0 =>
array (
'value' => '',
'_error_element' => 'default_value_widget][field_f2][0][value',
),
),
'default_value_php' => '',
'default_value_widget' =>
array (
'field_f2' =>
array (
0 =>
array (
'value' => '',
'_error_element' => 'default_value_widget][field_f2][0][value',
),
),
),
'group' => false,
'required' => 0,
'multiple' => '0',
'text_processing' => '0',
'max_length' => '',
'allowed_values' => '',
'allowed_values_php' => '',
'op' => 'Save field settings',
'module' => 'text',
'widget_module' => 'text',
'columns' =>
array (
'value' =>
array (
'type' => 'text',
'size' => 'big',
'not null' => false,
'sortable' => true,
'views' => true,
),
),
'display_settings' =>
array (
'label' =>
array (
'format' => 'above',
'exclude' => 0,
),
'teaser' =>
array (
'format' => 'default',
'exclude' => 0,
),
'full' =>
array (
'format' => 'default',
'exclude' => 0,
),
4 =>
array (
'format' => 'default',
'exclude' => 0,
),
),
),
);
$content['extra'] = array (
'title' => '-5',
'body_field' => '0',
'revision_information' => '20',
'comment_settings' => '30',
'menu' => '-2',
);
thx
yashesh bhatia
Yashesh Bhatia
$output .= dsm($form); works
$output .= dsm($form); works better :)
getting interesting..
tried a little experiment. added another form element to the cck using form alter..
this added another textfield "f3" which was disabled, however it did not disable the field f1. so it looks like a vanilla form element can be disabled but not a cck field. any thoughts ?
thx.
yashesh bhatia
Yashesh Bhatia
I hope this will help you
http://drupal.org/node/357328
I m also trying to disable it
Pragna J Bhalsod