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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Setting default State value in form
Pages: [1]

Author Topic: Setting default State value in form  (Read 2123 times)

josue

  • I post occasionally
  • **
  • Posts: 81
  • Karma: 7
    • PTP
  • CiviCRM version: 3.4.4, 4.1.1
  • CMS version: Drupal 6.24, Drupal 7.12
  • MySQL version: 5.0
  • PHP version: 5.2
Setting default State value in form
November 13, 2009, 02:40:20 am
hey folks,

this seems like it should be easy but i cannot get it to work. i want to set California as the default value for a new individual form.

this is what i have (which does not work). help please...

this is in a drupal module, running d6 & civi3.

if ( $formName == 'CRM_Contact_Form_Contact' ) {

/**     CRM_Core_Error::debug( $formName );
        CRM_Core_Error::debug( $form );
        exit( );
**/
        $defaults['address_1_state_province_id'] = 1004;
        $form->setDefaults( $defaults );

    }

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: Setting default State value in form
November 13, 2009, 08:23:25 am

try:

Code: [Select]
$defaults['address[1][country_id]'] = 1004;
$form->setDefaults( $defaults );

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

ccsfdave

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 3.3.3
  • CMS version: Drupal 6.20
  • MySQL version: 5.0.45
  • PHP version: 5.2.6
Re: Setting default State value in form
April 25, 2011, 10:16:41 am
Greetings,

In which file would I add code for this exact issue in CiviCRM 4.0 Alpha 2?

Also would the above code change for the new version?

Thanks,

Dave Geller

Business Analyst
The Innovation Office - Dept. of Technology
City & County of San Francisco

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Setting default State value in form
April 25, 2011, 03:34:58 pm
Hi Dave - You would do this in a separate Drupal module which you create for the purpose of implementing this (and potentially other) modification to CiviCRM behavior via hook(s). In this case, you would be implementing the "buildForm" hook:

http://wiki.civicrm.org/confluence/display/CRMDOC33/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmbuildForm

Intro to using hooks is in the online book Understanding CiviCRM (link above) - Extending and Customizing chapter.
Protect your investment in CiviCRM by  becoming a Member!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Setting default State value in form
April 25, 2011, 04:23:01 pm
We had this requirement as well & this is the function we used

Note that it didn't work everywhere but it was better than nothing. The customer would have preferred the ability to set a default state was built into CiviCRM core but doesn't funds to put towards that at the moment

function civifuzion_civicrm_buildForm( $formname, $form ){
 // default state = 1018 - set for new contact form (and preferably all backend forms)

  if ($form->_defaultValues['address'][1]['country_id']){
       $defaults['address'][1]['state_province_id'] = 1018;
       $form->setDefaults($defaults);

 }
}
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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Setting default State value in form

This forum was archived on 2017-11-26.