Hi
My other issue is that a country is required even if I de-select the Country field in "Customize fields to use".
In the help text, we're told:
"Note: normally, the following fields are REQUIRED but will not be (naturally) when not used: Country, State, Zip, City, Address"

however when I disable it, I get the following warning when trying to add billing info:

Illegal value for Billing address's Country field. You must select a Country from the dropdown list.

Though I didn't make address info required.

Do you have any idea why this is happening? I'd really like to not display the country (since this website is only for one particular state in the US).

Thanks,
Scott

Comments

rconstantine’s picture

I'll look into it. So to make sure I'm clear, the address itself is not required and the field is disabled, right? Do you have a default country specified?

scottrigby’s picture

correct:
- address "required" checkbox is not selected.
- field in 'customize fields to use' is not selected.

For a moment I thought maybe it was because I had "united States" selected in the 'Allowed Countries' fieldset. But I deselected it, saved the content type, then edited billing info for another user in a seperate browser and no dice. The same error as above.

should I add the devel module to help troubleshoot?

[I can do that tomorrow]

Thanks
Scott

rconstantine’s picture

Try replacing the following function with this code:

function theme_cck_address_display($form) {
  $output = '';
  asort($form['field_order']['#value']);
  foreach ($form['field_order']['#value'] as $field => $order) {
    if ($form['fielddisplay']['#value']['field_display_'.$field] === 'field_display_'.$field) {
      $output .= drupal_render($form[0][$field]);
    }
    else {
      if ($field == 'country' || $field == 'state') {//make it so if activeselect isn't used that we do make #access FALSE instead of this
        $form[0][$field]['#title'] = '';
        $form[0][$field]['#attributes'] = array('style' => "display:none");
      }
      else {
        $form[0][$field]['#access'] = FALSE;
      }
    }
  }
  $output .= drupal_render($form);
  return $output;
} //function theme_cck_address_display()

Sorry it isn't a proper patch.

rconstantine’s picture

And for the node display, try replacing this function too:

function theme_cck_address($cck_address, $field) {
  //create the output
  if ($cck_address['afd'] == 1) {
    $output = $cck_address['street1']. ' ';
    $output .= $cck_address['street2']. '<br />';
    $output .= $cck_address['city']. ', ';
    $output .= $cck_address['state']. ' ';
    $output .= $cck_address['zip'];
    $output .= '<br />';
  }
  else {
    $output = '';
    asort($field['field_order']);
    foreach ($field['field_order'] as $field2 => $order) {
      switch ($field2) {//TODO create more elaborate output based on $order; not I'm only now using it for display of other, assuming it will either be first or last
        case 'street1':
          if ($field['fielddisplay']['field_display_street1'] === 'field_display_street1' && isset($cck_address['street1']) && $cck_address['street1'] != '') {
            $output .= $cck_address['street1'] .' ';
          }
          break;
        case 'street2':
          if ($field['fielddisplay']['field_display_street2'] === 'field_display_street2' && isset($cck_address['street2']) && $cck_address['street2'] != '') {
            $output .= '<br />'. $cck_address['street2'];
          }
          break;
        case 'apt':
          if ($field['fielddisplay']['field_display_apt'] === 'field_display_apt' && isset($cck_address['apt']) && $cck_address['apt'] != '') {
            $output .= '#'. $cck_address['apt'];
          }
          break;
        case 'city':
          if ($field['fielddisplay']['field_display_city'] === 'field_display_city' && isset($cck_address['city']) && $cck_address['city'] != '') {
            $output .= '<br />'. $cck_address['city'] .', ';
          }
          break;
        case 'state':
          if ($field['fielddisplay']['field_display_state'] === 'field_display_state' && isset($cck_address['state']) && $cck_address['state'] != '') {
            $output .= $cck_address['state'] .' ';
          }
          break;
        case 'zip':
          if ($field['fielddisplay']['field_display_zip'] === 'field_display_zip' && isset($cck_address['zip']) && $cck_address['zip'] != '') {
            $output .= $cck_address['zip'];
          }
          break;
        case 'country':
          if ($field['fielddisplay']['field_display_country'] === 'field_display_country' && isset($cck_address['country']) && $cck_address['country'] != '') {
            $output .= ' '. $cck_address['country'];
          }
          break;
        case 'other':
          if ($field['fielddisplay']['field_display_other'] !== 0 && isset($cck_address['other']) && $cck_address['other'] != '') {
            if ($order > 1) {
              $output .= '<br />'. $cck_address['other'] .'<br />';
            }
            else {
              $output .= $cck_address['other'] .'<br />';
            }
          }
          break;
      }
    }
    $output .= '<br /><br />';
  }
  return $output;
} // function theme_cck_address()

If this checks out for you, I'll roll a new version.

rconstantine’s picture

Assigned: Unassigned » rconstantine
Status: Active » Needs review

Okay, my tests allow me to turn off everything a at least with the field not required at all, I was able to show only Address, City, ZIP, and Suite with no submission problems. Hopefully you find the same results. I'm off to check a couple of other combos.

rconstantine’s picture

Note, the above solution does not prevent the country and state from being stored, it uses the defaults. So make sure in your case that you set them.

rconstantine’s picture

Setting the overall required-ness for the field works; only the fields marked as visible become required for real and the submission works fine.

scottrigby’s picture

Great - this seems to work well, thanks!

should I try to turn this into a patch (I've never done that before , but I see the basic idea using + & -)?

PS, there's still an error when I go to edit the address field:

warning: Invalid argument supplied for foreach() in (path)/includes/form.inc on line 948.

Should I see this as a completely separate issue?

Thanks again
Scott

rconstantine’s picture

Did you save all cck fields again per my upgrade instructions?

If so, then yes, it should be another issue. Don't worry about making a patch. Now that you've tested this, I'll just do another release. But just to make sure your error IS a separate issue, please do the following for me...

Download and install the 'devel' module. Activate the 'backtrace' feature. You shouldn't have to activate anything else. Make sure your error reporting (standard Drupal feature) is set to screen and log, not just log. Then visit the offending page. You should get a reverse order list of function calls that made the error, including line numbers and arguments. Either copy the whole thing and post it here, or find the function and line from my module that is causing it and just give me that and the arguments. Then we'll decide whether it's another issue or not.

rconstantine’s picture

Status: Needs review » Fixed
scottrigby’s picture

I haven't done this yet (devel module, backtrace) - apologies - i was away and am now back working on this project. I have other issues to attend to on this, but will try to follow these steps later today. Thanks, Scott

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.