I'm using uc_profile module and select list does not turn to checkboxes on ubercart checkout form.
tried to allow checkboxes substitution on that form but does not work
form id is uc_cart_checkout_form

Comments

johnhanley’s picture

This is more than likely due to some sort of incompatibility with that particular module. In order words both modules are manipulating the profile form data via the hook_alter_form() function. To test, access the database table "system" and set the weight of Profile Checkboxes to "10". This should cause the hook_alter_form() function in Profile Checkboxes to run last. However this could cause the other module to operate incorrectly so you will probably have to discontinue use of one of them. Presumably this would be Profile Checkboxes since the other module is essential to Ubercart.

pokadan’s picture

Thank you.

johnhanley’s picture

Status: Active » Closed (fixed)
speedyboum’s picture

Submit.

jnettik’s picture

Version: 6.x-1.1 » 6.x-2.0

I'm using this module and I still can't get it to work with uc_profile. I've changed the weight, I've added uc_cart_checkout_form to this module's switch statement. Everything is still a select dropdown.

I also noticed that this module is a dependency to uc_profile. Just wondering if I'm missing something.

johnhanley’s picture

I also noticed that this module is a dependency to uc_profile. Just wondering if I'm missing something.

This module has no such dependency. You'll need to ask the maintainer of the UC Profile module.

jnettik’s picture

Yeah sorry about that. This is kind of an inherited site with some module hacks. Evidently this was one of them...

johnhanley’s picture

This is kind of an inherited site with some module hacks.

Oy, I feel your pain.

jnettik’s picture

Status: Closed (fixed) » Needs review

So after getting clean installs to work with of all necessary modules ;) I still ended up with the same problem as the OP. Anyway I was able to fix it by adding this code

    case 'uc_cart_checkout_form':
      global $user;

      $fields = profile_checkboxes_selection_fields($user->uid);

      while($field = db_fetch_object($fields)) {
        if (isset($form['panes']['uc_profile'][$field->category][$field->name])) {
          if (!$form['panes']['uc_profile'][$field->category][$field->name]['#required']) {
            // remove default selection element from options array
            // we can't use array_shift here because it resets numeric array keys to zero
            if (!empty($form['panes']['uc_profile'][$field->category][$field->name]['#options'])) {
              reset($form['panes']['uc_profile'][$field->category][$field->name]['#options']);
              unset($form['panes']['uc_profile'][$field->category][$field->name]['#options'][key($form['panes']['uc_profile'][$field->category][$field->name]['#options'])]);
            }
          }
          $value = unserialize($field->value) ? unserialize($field->value) : array($field->value);
          switch ($field->type) {
            case 'checkboxes':
              // change list selection field type from 'select' to 'checkboxes'
              $form['panes']['uc_profile'][$field->category][$field->name]['#type'] = 'checkboxes';
              $form['panes']['uc_profile'][$field->category][$field->name]['#default_value'] = $value;
              break;
            case 'radios':
              // change list selection field type from 'select' to 'radios'
              $form['panes']['uc_profile'][$field->category][$field->name]['#type'] = 'radios';
              if ($form[$field->category][$field->name]['#default_value'] == '0') {
                // profile module records empty field text value as zero (0) when input is not required
                // clear zero text value for pre-existing entry when radio button field is required
                // will otherwise produce "An illegal choice has been detected." message on submit
                $form['panes']['uc_profile'][$field->category][$field->name]['#default_value'] = '';
              }
              break;
            case 'multiple':
              // change single list selection to multi-select
              $form['panes']['uc_profile'][$field->category][$field->name]['#multiple'] = TRUE;
              $form['panes']['uc_profile'][$field->category][$field->name]['#default_value'] = $value;
              break;
          }
        }
      }
    break;

Basically the same thing you have going on with the profile pages, just targeting the specific pane in UberCart. So far I haven't had any problems with this and I'm testing it on uc_profile-6.x-2.x-dev. Not sure if this is something that could be added to the module at some point. I think it's a helpful feature.

johnhanley’s picture

@jnettik,

Thanks for the submission.

I'm unable to test the code myself (don't have the correct environment setup), but at a glance the code looks reasonable and could definitely be useful. I'm willing to roll it into the next release once it's reviewed and tested by the community.

Cheers,
John

johnhanley’s picture

Status: Needs review » Closed (won't fix)

I've decided the demand for this feature is very small and the above modification might be best suited for a custom module when the specific need arises.

Please feel free to reopen if I have underestimated the need for inclusion in Profile Checkboxes.