I have a module called CCK Taxonomy Super Select Ultra ;-) which started out as a combination between cck_taxonomy and taxonomy_super_select. It is supposed to support both multi-select (checkboxes) and single-select (radio buttons), but I've never been able to get the radios working. I'm trying again, and hope that someone here can help because this is the only real bug left!!!

You may want to download the module file and look at these functions: cck_taxonomy_ssu_widget, _cck_taxonomy_ssu_branch, _cck_taxonomy_ssu_nested.

The basic construction of the form starts in the widget hook, the top level of the form is made by branch, then nested repeatedly calls itself and branch recursively.

Because there is an unknown number of items before hand, and because I display everything hierarchically, I must use 'checkbox' rather than 'checkboxes' and 'radio' rather than 'radios'. I have no problems with the checkbox items. All are created correctly, passed to validation, processing, submission, and processing again just fine per normal CCK methods.

However, when I use 'radio', $form_values is missing nearly the entire tree of results. It is here that I am stuck. Here is what one node of checkbox looks like, followed by one node of radio:

case 'checkbox':
      if ($field['rate_yesno']) {
        $form['set'] = array(
          '#type' => 'fieldset',
          '#weight' => $fieldweight,
        );
      }
      $form['set'][] = array(
        '#type' => 'checkbox',
        '#title' => ($term->is_parent ? '<strong>' : '').t($term->name).($term->is_parent ? '</strong>' : ''),
        '#return_value' => $term->tid,
        '#default_value' => $value,
        '#weight' => $fieldweight,
        '#prefix' => $field['rate_yesno'] ? '<span style="clear:left; float:left; margin-right:2em;">' : '',
        '#suffix' => $field['rate_yesno'] ? '</span>' : '',
      );
      if ($field['rate_yesno']) {
        $choice_title = $field['choice_title'];
        $options = cck_taxonomy_ssu_choice_values($field);
        $form['set'][] = array(
          '#type' => 'select',
          '#options' => $options,
          '#default_value' => $choice_value,
          '#weight' => $fieldweight+1,
          '#prefix' => '<span style="clear:right;">',
          '#suffix' => '</span>',
          '#description' => $field['choice_title'],
        );
      }
    break;
case 'radio':
      if ($field['rate_yesno']) {
        $form['set'] = array(
          '#type' => 'fieldset',
          '#weight' => $fieldweight,
        );
      }
      $form['set'][] = array(
        '#type' => 'radio',
        '#title' => ($term->is_parent ? '<strong>' : '').t($term->name).($term->is_parent ? '</strong>' : ''),
        '#return_value' => $term->tid,
        '#default_value' => $value,
        '#weight' => $fieldweight,
        '#prefix' => $field['rate_yesno'] ? '<span style="clear:left; float:left; margin-right:2em;">' : '',
        '#suffix' => $field['rate_yesno'] ? '</span>' : '',
        '#parents' => array('tid'),
      );
      if ($field['rate_yesno']) {
        $choice_title = $field['choice_title'];
        $options = cck_taxonomy_ssu_choice_values($field);
        $form['set'][] = array(
          '#type' => 'select',
          '#options' => $options,
          '#default_value' => $choice_value,
          '#weight' => $fieldweight+1,
          '#prefix' => '<span style="clear:right;">',
          '#suffix' => '</span>',
          '#description' => $field['choice_title'],
        );
      }
    break;

The following is the form itself, and everything looks fine to me:

Form: Array
(
    [field_ccktssutest] => Array
        (
            [#tree] => 1
            [tid] => Array
                (
                    [#type] => fieldset
                    [#title] => Publication Topics
                    [#collapsible] => 1
                    [#collapsed] => 
                    [#weight] => 
                    [#description] => Users in charge of a publication (newsletter, magazine, etc.) should use this to categorize their articles. Articles tagged with a term from this listing will show up as eligible to be included in your publication.
                    [#attributes] => Array
                        (
                            [class] => cck-tssu
                        )

                    [select_parent] => Array
                        (
                            [#type] => select
                            [#title] => Parent
                            [#default_value] => 
                            [#options] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [option] => Array
                                                (
                                                    [X] => 
                                                )
                                        )

                                    [1] => stdClass Object
                                        (
                                            [option] => Array
                                                (
                                                    [640] => Health and Fitness
                                                )
                                        )

                                    [2] => stdClass Object
                                        (
                                            [option] => Array
                                                (
                                                    [643] => Lifestyle
                                                )
                                        )
                                )

                            [#description] => Select parent term to put your new term inside.
                            [#multiple] => 0
                            [#required] => 
                            [#size] => 0
                            [#weight] => 999
                            [#theme] => taxonomy_term_select
                        )

                    [term_name] => Array
                        (
                            [#type] => textfield
                            [#title] => Add a Term
                            [#default_value] => 
                            [#size] => 30
                            [#required] => 
                            [#maxlength] => 255
                            [#description] => Don't see a term that fits what you're looking for? Add your own. Select which term should be its parent in the drop down list above. Separate multiple terms by a comma.
                            [#weight] => 1000
                        )

                    [none] => Array
                        (
                            [#type] => radio
                            [#title] => Select None
                            [#return_value] => -1
                            [#default_value] => 
                            [#weight] => -10001
                            [#parents] => Array
                                (
                                    [0] => tid
                                )
                        )

                    [#required] => 0
                    [640] => Array
                        (
                            [#type] => fieldset
                            [#title] => Health and Fitness
                            [#collapsible] => 1
                            [#collapsed] => 1
                            [#weight] => -1001
                            [#description] => 
                            [#attributes] => Array
                                (
                                    [class] => cck-tssu
                                )

                            [select_parent] => Array
                                (
                                    [#type] => select
                                    [#title] => Parent
                                    [#default_value] => 
                                    [#options] => Array
                                        (
                                            [0] => 
                                            [1] => stdClass Object
                                                (
                                                    [option] => Array
                                                        (
                                                            [640] => *Health and Fitness*
                                                        )
                                                )

                                            [2] => stdClass Object
                                                (
                                                    [option] => Array
                                                        (
                                                            [641] => Running
                                                        )
                                                )

                                            [3] => stdClass Object
                                                (
                                                    [option] => Array
                                                        (
                                                            [642] => Walking
                                                        )
                                                )
                                        )

                                    [#description] => Select parent term to put your new term inside.
                                    [#multiple] => 0
                                    [#required] => 
                                    [#size] => 0
                                    [#weight] => 999
                                    [#theme] => taxonomy_term_select
                                )

                            [term_name] => Array
                                (
                                    [#type] => textfield
                                    [#title] => Add a Term
                                    [#default_value] => 
                                    [#size] => 30
                                    [#required] => 
                                    [#maxlength] => 255
                                    [#description] => Don't see a term that fits what you're looking for? Add your own. Select which term should be its parent in the drop down list above. Separate multiple terms by a comma.
                                    [#weight] => 1000
                                )

                            [641] => Array
                                (
                                    [set] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [#type] => radio
                                                    [#title] => Running
                                                    [#return_value] => 641
                                                    [#default_value] => 
                                                    [#weight] => -1
                                                    [#prefix] => 
                                                    [#suffix] => 
                                                    [#parents] => Array
                                                        (
                                                            [0] => tid
                                                        )
                                                )
                                        )
                                )

                            [642] => Array
                                (
                                    [set] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [#type] => radio
                                                    [#title] => Walking
                                                    [#return_value] => 642
                                                    [#default_value] => 
                                                    [#weight] => 0
                                                    [#prefix] => 
                                                    [#suffix] => 
                                                    [#parents] => Array
                                                        (
                                                            [0] => tid
                                                        )
                                                )
                                        )
                                )
                        )

                    [643] => Array
                        (
                            [set] => Array
                                (
                                    [0] => Array
                                        (
                                            [#type] => radio
                                            [#title] => Lifestyle
                                            [#return_value] => 643
                                            [#default_value] => 643
                                            [#weight] => 0
                                            [#prefix] => 
                                            [#suffix] => 
                                            [#parents] => Array
                                                (
                                                    [0] => tid
                                                )
                                        )
                                )
                        )
                )
        )
)

Here is the generated HTML:

<fieldset class="cck-tssu collapsible"><legend>Publication Topics</legend><div class="description">Users in charge of a publication (newsletter, magazine, etc.) should use this to categorize their articles. Articles tagged with a term from this listing will show up as eligible to be included in your publication.</div><div class="form-item">
 <label class="option"><input type="radio" name="tid" value="-1"   class="form-radio" /> <em>Select None</em></label>
</div>
<fieldset class="cck-tssu collapsible collapsed"><legend>Health and Fitness</legend><div class="form-item">
 <label class="option"><input type="radio" name="tid" value="641"   class="form-radio" /> Running</label>
</div>
<div class="form-item">

 <label class="option"><input type="radio" name="tid" value="642"   class="form-radio" /> Walking</label>
</div>
<div class="form-item">
 <label for="edit-field-ccktssutest-tid-640-select-parent">Parent: </label>
 <select name="field_ccktssutest[tid][640][select_parent]" class="form-select" id="edit-field-ccktssutest-tid-640-select-parent" ><option value="0">&lt;none&gt;</option><option value="640">*Health and Fitness*</option><option value="641">Running</option><option value="642">Walking</option></select>
 <div class="description"><a href="/anatolia/admin/help/taxonomy#parent">Select parent term to put your new term inside</a>.</div>

</div>
<div class="form-item">
 <label for="edit-field-ccktssutest-tid-640-term-name">Add a Term: </label>
 <input type="text" maxlength="255" name="field_ccktssutest[tid][640][term_name]" id="edit-field-ccktssutest-tid-640-term-name"  size="30" value="" class="form-text" />
 <div class="description">Don't see a term that fits what you're looking for? Add your own. Select which term should be its parent in the drop down list above. Separate multiple terms by a comma.</div>
</div>
</fieldset>
<div class="form-item">
 <label class="option"><input type="radio" name="tid" value="643"  checked="checked"  class="form-radio" /> Lifestyle</label>

</div>
<div class="form-item">
 <label for="edit-field-ccktssutest-tid-select-parent">Parent: </label>
 <select name="field_ccktssutest[tid][select_parent]" class="form-select" id="edit-field-ccktssutest-tid-select-parent" ><option value="X">&lt;root&gt;</option><option value="640">Health and Fitness</option><option value="643">Lifestyle</option></select>
 <div class="description"><a href="/anatolia/admin/help/taxonomy#parent">Select parent term to put your new term inside</a>.</div>
</div>
<div class="form-item">
 <label for="edit-field-ccktssutest-tid-term-name">Add a Term: </label>

 <input type="text" maxlength="255" name="field_ccktssutest[tid][term_name]" id="edit-field-ccktssutest-tid-term-name"  size="30" value="" class="form-text" />
 <div class="description">Don't see a term that fits what you're looking for? Add your own. Select which term should be its parent in the drop down list above. Separate multiple terms by a comma.</div>
</div>
</fieldset>

Here is $items (used by CCK):

Validate Items: Array
(
    [tid] => Array
        (
            [select_parent] => X
            [term_name] => 
            [640] => Array
                (
                    [select_parent] => 0
                    [term_name] => 
                )
        )
)

And finally, here is $form_values after submission:

Form values: Array
(
    [nid] => 719
    [vid] => 761
    [uid] => 1
    [created] => 1204067624
    [type] => test2
    [changed] => 1204083868
    [title] => Single select test
    [log] => 
    [name] => nforge
    [date] => 2008-02-26 15:13:44 -0800
    [status] => 1
    [promote] => 0
    [sticky] => 0
    [revision] => 0
    [moderate] => 0
    [preview] => Preview
    [op] => Submit
    [submit] => Submit
    [delete] => Delete
    [form_token] => a6f5e6aa4c257ec905b5a13fe263ab0a
    [form_id] => test2_node_form
    [comment] => 0
    [menu] => Array
        (
            [title] => 
            [description] => 
            [pid] => 1
            [path] => 
            [weight] => 0
            [mid] => 0
            [type] => 86
        )

    [path] => single-select-test
    [pid] => 2806
    [pathauto_perform_alias] => 1
    [field_ccktssutest] => Array
        (
            [tid] => Array
                (
                    [select_parent] => X
                    [term_name] => 
                    [640] => Array
                        (
                            [select_parent] => 0
                            [term_name] => 
                        )

                )

        )

    [tid] => 641
    [epublish_abstract] => 
    [og_public] => 1
    [og_groups] => Array
        (
            [1] => 1
        )

    [signup_enabled] => 0
    [signup_forwarding_email] => 
    [signup_send_confirmation] => 1
    [signup_confirmation_email] => This is to confirm that you will be reminded via email about %event which is to be held at %time.
    [signup_send_reminder] => 1
    [signup_reminder_days_before] => 1
    [signup_reminder_email] => This is your reminder for %event at %time.
    [signup] => 1
    [preview_changes] => Preview changes
)

If anyone can see what I'm doing wrong, please let me know. BTW, I'll probably go ahead and release a new version of the module tonight since this part wasn't working before anyway and I've got a lot of new code.

Help me Drupal-Wan-Kenobi, you're my only hope.

Comments

psboegh’s picture

How far is the debugging of this module reached. Is it ready for Drupal6 or if not at what stage do you need help?

Best regards

Phillip