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 (Moderator: Donald Lobo) »
  • Accessing QuickForm elements from Smarty
Pages: [1]

Author Topic: Accessing QuickForm elements from Smarty  (Read 798 times)

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Accessing QuickForm elements from Smarty
March 29, 2011, 11:18:14 am
I'm using Drupal's buildForm hook to add many element groups to a QuickForm at once.  How do I access it in my template override?  I haven't been able to find much in the way of how Smarty interacts with QuickForm.

I tried this in my template override:
Code: [Select]
      {section name=advFieldLoop start=1 loop=20}
          {assign var=idx value=$smarty.section.advFieldLoop.index}
          {$form.field_$i.html}
      {/section}

The code above produced no output.  Clearly there's something I don't understand about this.  The code I'm using to add the element groups is below:

Code: [Select]
function mymodule_civicrm_buildForm($formName, &$form) {
    if ($formName == 'CRM_Event_Form_ManageEvent_Fee') {
       for ($i = 1; $i <= 20; $i++) {
           $field[] = &HTML_QuickForm::createElement('text','Name','name');
           $field[] = &HTML_QuickForm::createElement('text','Machine Value','value');
           $field[] = &HTML_QuickForm::createElement('checkbox','Is a filter?','filter','Is filter?');
           $form->addGroup($field,'field_' . $i,'Field ' . $i,' ');
       }
    }
}

Thanks.

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: Accessing QuickForm elements from Smarty
March 29, 2011, 03:41:55 pm

a few tips:

1. Can u check and see if:

Code: [Select]
{$form.field_1.html}

works? if so, then u'll need to create another smarty variable called fieldIDX and set that to field_$i and then use $form.$fieldIDX.html

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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Accessing QuickForm elements from Smarty

This forum was archived on 2017-11-26.