For a user that has signed up through the drupal register interface (as opposed to Ecommoerce, checkout or ec_anon), address module prints a form in checkout with a country selector at the top.

The State/Province field is not marked with * as required, however if it is left blank, drupal returns the message: Please enter a state/province/region.

See screenshot

CommentFileSizeAuthor
#7 module_4.patch2.23 KBbrmassa
#6 javascript.patch1.97 KBbrmassa
screenshot_34.png251.47 KBBevan

Comments

Bevan’s picture

gordon’s picture

Status: Active » Closed (works as designed)

This is a issue with the formapi. These fields are not required but at least 1 needs to have data in it.

Bevan’s picture

which fields are "these fields"? Please see the screenshot -- i'm not sure if you understood the issue. but then I'm not sure if I understand your explanaition either.

gordon’s picture

Province/Region and state are 2 separate fields, and only it only needs 1 field to be populated to be a valid form.

In your image the state field is hidden but it is there.

In the formapi which generates all the forms in Drupal the is no way to add the red * with having the 2 fields being required.

elio’s picture

Flexycharge doesn't work with anon_address, is it a bug? I use flexycharge to shipping cost and buying a with ec_anon will charge the defaut.
It's very bad, makes ec_anon uneusable.... can I contribute?

brmassa’s picture

Version: 5.x-3.0-beta3 » 5.x-3.0
Assigned: Unassigned » brmassa
Status: Closed (works as designed) » Needs review
StatusFileSize
new1.97 KB

Gordon and Bevan,

there is a attribute called "#DANGEROUS_SKIP_CHECK" that permits changing the field using javascript. so i created a patch that instead using "state" and "province" fields, the javascript replace entirelly a input for a select field.

it goes further than the patch i created on http://drupal.org/node/135477.

best regards,

massa

PS: state is considered required despite many users asking for not.

brmassa’s picture

StatusFileSize
new2.23 KB

and the .module patch

Bevan’s picture

Cool! I actually ditched user-registration in favor of ec_anon for this project. Does this patch apply to ec_anon also? Can you provide a screenshot please?

tks

gordon’s picture

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

I am not going to go any further with this. The proposed fix is just over blown just to be able to add a red *

This is something that is just not available in the current Drupal formapi.

brmassa’s picture

@ Bevan,

The general appearence is exactly the same as before.
I dont use ec_anon. But it corrects all Address creating/editing forms. It might work.

@ Gordon,

i think you underestimated the patch: it corrects 3 BUGS and add 1 FEATURE!

  1. Interface BUG: state and province are considered internally required but its not presented as so.
  2. Validation BUG: using current code, its IMPOSSIBLE to change/edit the current state/province once created.
  3. Custom states BUG: store_location.inc says that its possible to create a custom states list for other countries, although its wil not work due php and javascript errors.
  4. No-Javascript FEATURE: without javascript enabled, the current shows both "state" and "province" fields, while the patch only shows state field as a textfield. It degrades gracefully.

As i said before, i believe that making state a required field is not right, since some countries dont have states or provinces. Its is a undesirable feature. but since its is required, it is a interface BUG. I suggest you simple delete the "#require" => true line.

I know the solution is not elegant, but i believe that somewhat ugly code is better than a buggy code.

FormAPI provides the "#DANGEROUS_SKIP_CHECK" attribute for exactly these sittuations where fields should be dynamically created. There are some modules that use the same tech, including dynamic address (!!), like http://drupal.org/node/102294.

best regards,

massa

gordon’s picture

Yes maybe but this cannot be ported to the 4.7 version, and we are redeveloping all this for v4 so it is not needed.

kingandy’s picture

The address.module includes a check for a variable named 'store_ignore_state' but this does not appear to be configurable anywhere.

/**
 * Validate an address being saved
 */
function address_form_validate($form_id, $form_values) {
  if ( variable_get('store_ignore_state', FALSE)) {
    return;
  }
  if (!$form_values['province'] && !$form_values['state']) {
    form_set_error('state', t('Please enter a state/province/region.'));
    form_set_error('province', '');
  }
}

I'm given to understand that since hook_settings was removed for 5.0 this would require manual creation of a menu callback, doing something like the following:

function address_admin() {

  $form['store_ignore_state'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore state/province/region?'),
    '#default_value' => variable_get('store_ignore_state', FALSE),
    '#description' => t("If this option is checked, state/province/region will not be required on address forms.")
  );

  return system_settings_form($form);
}

Then something like this needs to be added to the address_menu function:

  if ($may_cache) { // line 16 of the current address.module
    $items[] = array(
      'path' => 'admin/ecsettings/address',
      'title' => t('Address module settings'),
      'description' => t('Configure the Address module.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => 'address_admin',
      'access' => user_access('access administration pages'),
      'type' => MENU_NORMAL_ITEM,
     );
  } // line 17 of the current address.module

I'm not terribly familiar with the new module settings system but hopefully that will point somebody more experienced in the right direction.

Additionally, the following lines could be added to the address_form_fields() function:

  $store_ignore_state = variable_get('store_ignore_state', FALSE);
  if ($store_ignore_state) {
    $form['state']['#required'] = TRUE;
    $form['province']['#required'] = TRUE;
  }

... but I'm even less knowledgeable of the innards of the ecomm system than I am of the module config system, so that might not be idea.

Hope that helps.