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 (Moderator: Dave Greenberg) »
  • Here's how to add attributes to form elements
Pages: [1]

Author Topic: Here's how to add attributes to form elements  (Read 300 times)

publicradio

  • I’m new here
  • *
  • Posts: 2
  • Karma: 3
  • CiviCRM version: 4.2.14
  • CMS version: Drupal 6x
  • MySQL version: 5
  • PHP version: 5
Here's how to add attributes to form elements
October 21, 2014, 10:40:26 am
Hi, I was able to sort this out, thanks to a helpful member of CiviCRM's IRC chat room, so I wanted to share this solution here, in case anyone needs it.

Say you have a form on a contribution page, and you want HTML5 placeholders in the fields. Well, you can create a new extension, install it, and in it use a function like this:

Code: [Select]
function client_civicrm_buildForm($formName, &$form) {
if($formName == 'CRM_Contribute_Form_Contribution_Main' && $form->getVar('_id') == 15) {
$form->updateElementAttr('street_address-3',array('placeholder' => 'xxxxxxxxxxxxx'));
}
}

Where 'client' is the name of your extension and 'street_address-3' is the id of your form field.

publicradio

  • I’m new here
  • *
  • Posts: 2
  • Karma: 3
  • CiviCRM version: 4.2.14
  • CMS version: Drupal 6x
  • MySQL version: 5
  • PHP version: 5
Re: Here's how to add attributes to form elements
October 21, 2014, 02:21:32 pm
also: when you have a select dropdown, the default option says '-select-'. If you want to change this, you can use this code:

Code: [Select]
if ($form->elementExists('country-3')) {
$e = $form->getElement('country-3');
$e->_options[0]['text'] = 'zzz';
    }

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Here's how to add attributes to form elements

This forum was archived on 2017-11-26.