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) »
  • $formName and $defaults[] in hook_civicrm_buildForm()
Pages: [1]

Author Topic: $formName and $defaults[] in hook_civicrm_buildForm()  (Read 1408 times)

jperickson

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
$formName and $defaults[] in hook_civicrm_buildForm()
August 22, 2010, 03:25:11 pm
Hello. I would like a certain event type to be the default for all new events, and for the users not to see the drop-down for Event Type selection in the New Event form. I know how to create the EventInfo.tpl template to remove the drop-down, but since this is a required field, removing it does not solve the problem as you still get the error saying it was not selected. Therefore, I would like to create a default event type so that any event created without the drop-down will create an event without an error message and be of this certain default event type. Does anyone have a good idea on how to do this?

I've been trying to use hook_civicrm_buildForm() to do this, but I have a few questions beyond "Will it work?"

1) What is the value of $formName for this form? Is this documented anywhere?

2) Is $defaults[event_type_id] the proper variable to set the default to?

Thank you all for your help!

JE

jperickson

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
Re: $formName and $defaults[] in hook_civicrm_buildForm()
August 22, 2010, 03:41:37 pm
Here is what I am attempting:

function panelproposal_civicrm_buildForm($formName, &$form) {
  if ($formName == 'CRM_Event_Form_Event') {
    $defaults['event_type_id'] = 8;
    $form->setDefaults($defaults);
  }
}

So far it is not working. Any ideas? Thanks again.

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: $formName and $defaults[] in hook_civicrm_buildForm()
August 22, 2010, 07:03:44 pm

1. did u enable the module

2. put a debug statement as the first line of the function and check that the hook is called

3. you can also change event type id to be a hidden element with the value of 8

4. since u r in NY, u might want to consider attending developer camp where we cover the above and a whole lot more :)

http://civicrm.org/civicrm/event/info?reset=1&id=62

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

jperickson

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
Re: $formName and $defaults[] in hook_civicrm_buildForm()
August 22, 2010, 08:31:07 pm
Hey Lobo,

Thanks for the invite. I wish I could make it, but I have to be at my day job.

So I added a few watchdogs and I discovered that the hook is being called but the statement if ($formName == 'CRM_Event_Form_Event') is evaluating to false. Do you know the $formName for the New Event form?

As to your hidden field suggestion, where is the HTML for the form actually defined? I know that the smarty template has {$form.event_type_id.html} but I was not able to find the PHP file that defines those variables.

Thanks again for all of your help. I'm really new to all of this, and I greatly appreciate all that you do.

JE

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: $formName and $defaults[] in hook_civicrm_buildForm()
August 22, 2010, 08:37:55 pm

you should put a print statement in the hook to find the form name. you might want to read the chapter:

http://en.flossmanuals.net/CiviCRM/DevelopIntro
http://civicrm.org/architecture

to get a better idea of the code base and developing around civicrm

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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • $formName and $defaults[] in hook_civicrm_buildForm()

This forum was archived on 2017-11-26.