I have a site using Profile2 with address_field Module; and I would like to prevent users from filling out the follwing fields: Address 1 Address 2 ZIP Code Country

The goal is is only to be able to fill only CITY AND STATE; (e.g. Orlando, FLORIDA)




in a hook_form_alter() add:


you can use dpm($form['field_address']['und'][0]) to get the name of the city, and country fields.

You could also use CSS to hide the fields but I ran into problems where browsers prefilled those fields. It's better to hide it with a hook.

| improve this answer | |
  • you solution is good (y) – Yuseferi Apr 10 '14 at 9:52

Refer to the address-hide-country.inc file in the address module. It has given a good example of how to hide the country field.

Also there is an example module for how to create an address field plugin to create custom plugin to act on the address field.

| improve this answer | |

You can hide the country by checking the "Hide the country when only one is available" box in the field settings for your address field. Then you can add the following code to custom module to hide the Address1, Address2, and ZIP (where "MYMODULE" is the name of your custom module, "MYPROFILETYPE" is the machine name of the profile type you are altering, and MYFIELD is the name of your address field):

 * Implementation of hook_form_profile2_edit_PROFILE_NAME_form_alter()
function MYMODULE_form_profile2_edit_MYPROFILETYPE_form_alter(&$form, &$form_state){
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.