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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Hide an element in hook_civicrm_buildForm
Pages: [1]

Author Topic: Hide an element in hook_civicrm_buildForm  (Read 3954 times)

dsdart

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 3
  • CiviCRM version: 4.4
  • CMS version: Drupal 7.25
  • MySQL version: 5.1.41
  • PHP version: 5.3.1
Hide an element in hook_civicrm_buildForm
July 23, 2013, 12:44:52 pm
How can I hide an element, specifically an option of a select field, in hook_civicrm_buildForm?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Hide an element in hook_civicrm_buildForm
July 23, 2013, 12:51:06 pm
Do something like this:

Code: [Select]
/**
* Implements hook_civicrm_buildForm().
*/
function FIXME_civicrm_buildForm($formName, &$form) {
  // Alter contribution forms
  if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
    foreach ($form->_elements as &$e) {
      if (!empty($e->_attributes['name']) && $e->_attributes['name'] == 'custom_123') {
        unset($e->options['foo']);
      }
    }
  }
}
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Hide an element in hook_civicrm_buildForm

This forum was archived on 2017-11-26.