CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • State/province data
Pages: [1]

Author Topic: State/province data  (Read 1212 times)

aeranis

  • Guest
State/province data
August 15, 2009, 02:37:05 am
I am trying to make it so that state/province is a required field in my form, but since some countries do not have a listing, this is obviously not possible.  Is there a simple way to make it so that the state field no longer becomes required when a country that does not have provinces is checked? 

Or, is there a way to go through and manually add ' N/A ' as an option for every country that does not have provinces?  If so, where is this data located?

Apologies for my ignorance- I know next to no PHP  ...

Thanks in advance,
Arman

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: State/province data
August 15, 2009, 04:24:50 am
If you run this query you can see all the countries with no state/provinces

select * from civicrm_country left join civicrm_state_province on civicrm_country.id = civicrm_state_province.country_id where civicrm_state_province.country_id is null

the civicrm_state_province table holds all the state provinces.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: State/province data
August 15, 2009, 06:14:10 am

a couple of options:

1. modify the db and insert N/A records for all countries that dont have states

2. write a custom validate hook. THis checks if a country has states and if so makes it required.

I think route 2 is better and cleaner but does require some knowledge of php/mysql :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

aeranis

  • Guest
Re: State/province data
August 16, 2009, 03:40:07 pm
Does anyone have any examples of validation hooks for this purpose?
It seems like it should be pretty simple- "if country id does not appear in the country_province database, then the field is no longer required, and hide the field."  Since I don't know any PHP, I don't really know how to express this.
« Last Edit: August 16, 2009, 03:41:39 pm by aeranis »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: State/province data
August 16, 2009, 04:07:55 pm

there is an example of a validation hook here:

http://svn.civicrm.org/civicrm/branches/v2.2/drupal/civitest.module.sample

(search for _validate)

this gives you a start. you'll need to implement (or hire someone or barter etc) for the relevant php/mysql code

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • State/province data

This forum was archived on 2017-11-26.