0

I have a webform with some fieldsets. Within each fieldset is a set of input elements that are the same for each fieldset, and each set of elements has the same machine name.

One of the elements is a "Select options" as a set of checkboxes. I want to conditionally make some checkboxes readonly or disabled for all of the fieldsets.

My problem is that I have spent hours looking at how to do that, and I cannot find the elements within the $form object in order that I may alter them. The form is a multi-page form, so that may cause some problems, as I don't know if all of the elements show up in the submitted array until you have reached a specific page or not. I don't know how that works.

Part of my form has something like this:

outer_fieldset
-- count
-- fieldset_1
-- -- name
-- -- date
-- -- group
-- -- checkboxes
-- fieldset_2
-- -- name
-- -- date
-- -- group
-- -- checkboxes
-- fieldset_3
...

I used die('<pre>' . print_r($form['submitted']['outer_fieldset'], TRUE) . '</pre>'); to look at the data. $form['submitted']['outer_fieldset']['fieldset_1'] exists, but it doesn't have any elements inside it for the checkboxes or anything.

All the existing SE pages I have looked at give basic answers like $form['submitted']['element_name']['#attributes']['disabled'] = TRUE;, but I cannot use something like that unless I can find the element objects...

Could the fact that the inner controls all have the same machine name be causing a problem with that? The webform was created using the Drupal interface, and it allows controls to be added this way. I'm relatively new to Drupal. Any help on how to find and alter the attributes of these elements would be great. Thanks.

0

I found the checkboxes. I was printing the $form variable in the wrong hook function. I needed to do my modifications to the form in hook_form_alter.

I ended up using something like this:

unset($form['submitted']['outer_fieldset']['fieldset_1']['checkboxes']['#options'][$option]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.