With the latest release, Address Field seems to have taken a big step forward for its original purpose of supporting addresses for Commerce (delivering packages, etc.), but at the same time taken a big step backward for providing all-around support for an address field type in Drupal that is flexible and useful for a variety of content types and business cases.

The project page says as much when it says "This module was initially developed to support address storage in Drupal Commerce customer profiles, but it is now used by a wider variety of modules dealing with physical addresses and mapping."

May I suggest rolling back the enforced requirement for country-specific postal address fields until a function can be added to configure it as an optional choice, perhaps even by content type?

Ideally this choice would be a simple checkbox at the Content Type / Manage Fields that says something like "Require conformity to country-specific postal standards".

Thoughts? Am I alone here? (I see that this issue has been discussed on a number of Fixed issues, so I thought it best to open a new issue. Close it as Duplicate if you would prefer this get handled elsewhere.)

Comments

bojanz’s picture

Title: Allow Addressfield to support higher granularity of addresses than postal » Add an option for allowing incomplete data to be saved

What you need to understand is that the module never supported skipping per-country required fields. You (and other people) were relying on a buggy implementation of the "optional addressfield" functionality, where the required markers were stripped for optional fields to allow people to save a completely empty addressfield.
So, no decision was made to limit the module's use cases, a bug was fixed and it exposed the real problem for your use case.

I see your point, and will investigate adding a plugin with the new feature (making all fields optional).

A related use case is hiding the unneeded fields completely. Right now addressfield ships with plugins that hide the street address and postal code, which should be relevant to some use cases.

bunthorne’s picture

I understand your point about the original design and intent, but I am advocating for a broader use case that still confines itself to a core problem: providing country-specific address fields that integrate with BOTH postal and mapping functions (specific use cases supported by companion modules, perhaps).

My primary need is to be able to locate productions (performances at venues) around the world, both upcoming and historical. For historical data, I only need to know that a production played in a particular city -- I don't necessarily need the name of the theatre or its street address. For production companies, I am happy to include the full postal address if it is available, but some smaller groups are less established and don't publish a formal address. I only need to know what city they are in.

For now, I am mainly just using filters to display data in tables; I haven't moved forward to mapping--but I don't see why I couldn't given a country/city or down to the street address if I have it.

I wasn't aware of the plugin to hide street address and postal code. Unfortunately, that will probably not allow me to use postal code for contemporary venues (if I have it) and leave it blank for historical data (where it would be anachronistic anyway). I would need to be able to display the field but not require it.

jsibley’s picture

I believe that issue #2282817 #4 has code that can be put into a module to make fields visible but optional.

If someone could add a user interface allowing developers to check of which fields are optional rather than having to modify the code in that module, I think that this would provide the flexible solution that some of us are hoping for. Unfortunately, I'm not enough of a coder to volunteer to do that.

Also, in terms of use cases, some mapping solutions can map incomplete addresses (e.g., just a postal code), so it is possible to show at least some locations on a map (although the location may seem more exact than it is without additional context) even when there isn't a complete address (in my case, some users don't want their exact address to be shared).

Thanks for considering this potential added functionality.

alemadlei’s picture

Hey,

I tried to update the latest beta with this version. A little info regarding setup.

Address field (not required), only US address. Country is hidden as it is the only option.

On one form, using display suite, the addressfield is place under "Hidden".

(Address is stored on a separate form).

After trying to save, user sees message of required fields, but to them being hidden by DS, they cannot set this (and they shouldn't as it is a business rule).

So this update breaks our current site setup. Maybe this could happen to other users.

The notes mention
Created the concept of an address format.
An address format is an array which contains the per-country list of used fields, list of required fields, and the field labels.

Is there a way to alter them (hook maybe)?

bojanz’s picture

@alemadlei
Yes, you can use hook_addressfield_address_formats_alter(), it's documented in addressfield.api.php

alemadlei’s picture

So, with this I should be able to remove the requirements for all address fields all over site?

bojanz’s picture

@alemadlei
Yes, though I think the solution I posted in #2282817: How to make only the country required is more correct.
(You are not altering an address format, you're turning off all validation).

Perignon’s picture

Adding a +1 to this thread. I am looking forward to this option. I will have to implement the custom module to disable the required fields.

I think you introduced a huge problem putting #required => TRUE on the form elements because when a form gets created FAPI sees the sub fields being required an will not allow the form to be submitted. Setting the address field as a whole to not be required has no affect because the sub elements that create the field widget have #required => TRUE and so Drupal requires the fields.

My case as an example. I have an addressfield attached to the user profile. It is set to not be required but I cannot edit a user now without filling out the fields for name, address, city, state, and zip (US address).

I am certain if there is anyone using the Addressfield for things outside of Commerce this is going to cause some serious issues on their site. I already have had users send in support tickets because they cannot update their profile without providing an address which they do not want to do (we have never required it to give freedom to the user if they want that information known to us).

Any help I can give coding wise, please let me know. I am more than willing to help write a solution to this problem.

bojanz’s picture

I think you introduced a huge problem putting #required => TRUE on the form elements because when a form gets created FAPI sees the sub fields being required an will not allow the form to be submitted. Setting the address field as a whole to not be required has no affect because the sub elements that create the field widget have #required => TRUE and so Drupal requires the fields.

No, setting the country back to "None" makes the other fields disappear and not be required anymore.
This is still a bit buggy in rc1, but works fine in -dev. Maybe your users are not getting this behavior?

In any case, a patch for this issue is on my todo list.

Perignon’s picture

No, setting the country back to "None" makes the other fields disappear and not be required anymore.
This is still a bit buggy in rc1, but works fine in -dev. Maybe your users are not getting this behavior?

That is true, but still remains the fact that it has caused issues on sites that already had this module in place. Being that 92% of my customers are from the US, we defaulted the field to the US to make the user experience better for the majority of our clients.

Look forward to the patch. Again, I will be willing to offer help!

bojanz’s picture

@Perignon
So what you're attempting is to replicate the same broken behavior you had before: the user is shown a US address form, doesn't fill it out, but the data gets saved into the database anyway, potentially incomplete. Understood.

Perignon’s picture

@bojanz Absolutely! You ask for demographic data you never force it. In the world of mass email marketing and pay per click advertising, forcing the user to provide you too much information could and often does mean a loss of a conversion, a loss of a customer, a loss of potential sale. I send over 2 million emails a month in email marketing and use landing pages to convert people to potential customers. I also push a substantial amount of sales through Drupal Commerce. Just like the person posted here: https://www.drupal.org/node/2395729#comment-9478013 these fields being required, even though he did not require the addressfield as a whole, made his landing page for conversions require users to give an address. In his case and mine as well demographic data is very important but a sales lead is far more important.

bojanz’s picture

Status: Active » Needs review
FileSize
1.04 KB

Here's an initial patch.

It adds a plugin displayed as "Make all address fields optional (Not recommended)".
It makes the street, postal code, dependent locality, locality, administrative area optional.
Note that if you have a name field (or first_name/last_name fields), that stays required since it's generated by its own plugin.

What do you guys expect here, to have the name optional as well or not?

Perignon’s picture

Got the patch and it applies ok. But the problem is still there. The first and last name are still being required as you stated above. That isn't a viable solution as I still have to write a bandaid in custom module to stop this behavior.

Can we not make Addressfield obey the core field settings? I have told Drupal that this is not a required field but the code in Addressfield is trumping that setting (see attached screenshot). Addressfield should obey the Drupal core setting first. If required is set to FALSE for the field there should be nothing in Addressfield's sub fields required at all. Core setting should override all subfields.

bojanz’s picture

Status: Needs review » Needs work

@Perignon
Saying that the name should also be made optional is enough. I'll reroll the patch.

"Required" has different meaning when there are subfields involved, and your suggestion to treat it not being checked as "Optional, with validation off" is what prompted 250 comments over 3 issues in this issue queue. You're free to go and read them if you want the background on this problem.

Perignon’s picture

@bojanz No problem. I am unaware of the threads you are referencing. I feel your pain with developing modules as I have a basket case on my hand. I just always obey Drupal coding standards and one thing I hold valuable is not messing with core/hacking core. In my world this just violated Drupal core by overriding core fields module operation. Addressfield is a bear I know, because it's trying to be agnostic which can be very, very hard (I maintain Storage API). So not trying to give you a hard time. Just this update broke a lot of things on my site and irritated many of my users, I can't afford to do that and stay in business as you probably understand :-)

bojanz’s picture

Status: Needs work » Needs review
FileSize
1.38 KB

Rerolled the patch.

Perignon’s picture

Status: Needs review » Reviewed & tested by the community

Patch is good!

bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thank you for testing.

  • bojanz committed bb8d27a on 7.x-1.x
    Issue #2396975: Add an option for allowing incomplete data to be saved
    
jay.lee.bio’s picture

Status: Fixed » Reviewed & tested by the community

I've been using a temporary solution (https://www.drupal.org/node/2282817, #4) during the past few days. I'm confirming that #17 does exactly the same thing (after choosing the "Make all fields optional (Not recommended)" checkbox option). Thanks a bunch!

jay.lee.bio’s picture

Status: Reviewed & tested by the community » Fixed

Hmmm, it seems Drupal just changed the status by itself.

bunthorne’s picture

Thank you so much for moving on this, bojanz. Perhaps I can help offer some text/help around this topic. I think we have identified two distinct use cases (among many, perhaps) for the module: one is for Postal Addresses (with standards-based international validation), the other is as a location-identifying set of fields using international civic addressing components.

Perhaps we can get a paragraph or two onto the project page to guide the initial set up for the different cases.

tyler.frankenstein’s picture

Status: Fixed » Needs work

This works great except for the "Company" field, it is still required even when the "Make all fields optional (Not recommended)" checkbox checked. I thought the following code/patch in addressfield_format_address_optional() would do the trick, but it doesn't seem to be working:

if (isset($format['organisation_block'])) {
  $format['organisation_block']['organisation_name']['#required'] = FALSE;
}
bojanz’s picture

@tyler.frankenstein
$format['organisation_block']['organisation_name'] doesn't have #required to set to TRUE in organization.inc.
And by default on my install it's not required. So you'll need to figure out what's making it required first.

tyler.frankenstein’s picture

Status: Needs work » Fixed

@bojanz, you're right. I was being dumb and forgot about a custom module which was forcing the Company field to be required. I've since removed that customization, and the Company field is optional.

Status: Fixed » Closed (fixed)

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