Community Documentation

HowTo Create a 'country' profile field

Last updated November 30, 2010. Created by Tresler on February 13, 2007.
Edited by vensires, bekasu, alexanderpas, rootwork. Log in to edit this page.

This page describes how to create a 'country' field in your users' profiles, similar to the one on Drupal.org, that lets you easily find users in any country.

  1. Create a new profile field.
  2. Go to the profile settings page (administer > settings > profiles ?q=admin/user/profile)
  3. Select the 'list selection' type of form field.
    • Category (required): It can be a category you already have or a new one. (Suggested: Personal Information)
    • Title (required): Anything is OK. (Suggested: Country)
    • Form name (required): Anything is ok, as long as it is unique. (Suggested: profile_country)
    • Explanation (optional): Usually, country is self explanatory, but you may want to write a note here to your users about this field.
    • Selection options:
      Defining a comprehensive list of sovereign states is a contentious diplomatic and political issue. Several lists exist on the Web:
    • Weight: Select whatever you like (this is the weight in the category selected above).
    • Visibility: Select one of the 'Public Field' options.
    • Page title (required): You must put something here. (Suggested: People who live in)
    • Check boxes: Check 'the user must enter a value' to make this field required. Check 'visible in user registration form' to make it part of user registration.
  4. Click on 'Save field.'

Due to the constantly changing nature of this data, it is often best to compose your own data from up-to-date information provided in the above links.

Country Codes API

There's a module (Country Codes API: http://drupal.org/project/countries_api ) that provides PHP API calls for translating country codes into official short names" by mechfish at http://drupal.org/node/402198#comment-1551426

Comments

Thanks.

Thanks.

D7 has an API for country

First option is always selected

Using Check boxes: Check 'the user must enter a value' to make this field required does not make any sense, since the first option of "selection options" is always selected. So all users that "don't enter a value" are simply from Afghanistan.
How can an empty first value be inserted in "selection options" (no coding please)? Isn't there a defined expression for that in Drupal?
Just putting an "Enter" disappears and using --- or [please select] simply convert into a (weird) additional option.
Please inform

I started with Drupal in 2007 and then my life got stuck...

Blank option please??

Same goes for "gender" if you creat that field and even worse, date of birth.
On not selecting anything (which IS possible even if you have required switched on) all users are male (depending on the order of course) and born TODAY, and together with the former (country) all from Afghanistan.

I started with Drupal in 2007 and then my life got stuck...

Workarounds???

Hello again, no answers in some weeks, as is common in Drupal, but I need to resolve problems, so I continued to struggle on my own.
On thing that occurs to me to solve the lack of a default blank option to really force users for "required fields" is of course a workaround, as also is common in Drupal, even for the most basic functions.

requiered fields: country, gender, date of birth

country list: |, Afghanistan, Albania, Algeria, etc..... (the "|" does not generate a blank field, but at least looks almost empty on the form)
gender list: |, male, female
date: cannot be managed, starts with date of today

SO... what if, when either of the select fields return the "|" it is treated as an empty field and users are redirected back to the form, and gently asked to make a selection.
and if the date is "today", same procedure.

No idea how to code this, but I suppose this (or any other solution) would be interesting for anyone who doesn't want to have 90% of male users from Afghanistan who are born today.

I started with Drupal in 2007 and then my life got stuck...

thanks, but...

... My obsession these days is to find out how to make -for example- a dependent set of dropdowns in the user registration form that in one dropdown shows, by instance, the values of DOGS and CATS, and in the other dropdown, since it is dependent from the previous one, when the user has chosen "DOGS" this 2nd dropdown shows BOXER, BULLDOG and FOX TERRIER. Both dropdowns are required and both dropdowns retrieve their respective data from tables i have been previously set.
Any idea how to accomplish this? Is profile2 the module to use?

thanks a lot

PIÑA&POLLO

nobody click here