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) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Adding 'duration' to Form:CRM_Contact_Form_Task_Email
Pages: [1]

Author Topic: Adding 'duration' to Form:CRM_Contact_Form_Task_Email  (Read 714 times)

aeszq

  • I post occasionally
  • **
  • Posts: 53
  • Karma: 0
Adding 'duration' to Form:CRM_Contact_Form_Task_Email
April 12, 2013, 12:05:37 am
Hi,

I am creating an extension to add duration field into the form CRM_Contact_Form_Task_Email. The duration field is pretty much the same 'duration' field in the activity form.

I have added hook:
/**
 * Add duration to form: CRM_Contact_Form_Task_Email
 */
function emailduration_civicrm_buildForm($formName, &$form) {
  if ($formName == 'CRM_Contact_Form_Task_Email') {
    if ($form->getAction() == CRM_Core_Action::ADD) {
      $form->add('text', 'duration', ts('duration'), 'size=50 maxlength=4', TRUE);
    
      $form->addRule('duration',
      ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'
      );
    }
  }
}
and a customized template so that the duration filed is displayed on the form. However, I'm having difficulties saving the duration's value back to the civirm_activity table. I'm not sure how to get the values of activity_id and duration.
Here is the hook i have created:

function emailduration_civicrm_postProcess($formName, &$form) {
      if ($formName == 'CRM_Contact_Form_Task_Email') {
          $query = "
            UPDATE civicrm_activity
            SET duration = %1
            WHERE id = %2
         ";

       $params = array( 1  => array( $form['duration']['value'], 'Integer' ),
                              2  => array( $form['activity_id'], 'Integer' ));             
   
        CRM_Core_DAO::executeQuery( $query, $params );
    }
}

I have got error "Cannot use object of type CRM_Contact_Form_Task_Email as array", which is caused by  $form['duration']['value'] and $form['activity_id']

Do you guys have any ideas of the correct way to get the duration and activity_id?

Thanks,
George
« Last Edit: April 12, 2013, 12:14:43 am by aeszq »

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Adding 'duration' to Form:CRM_Contact_Form_Task_Email
April 12, 2013, 06:30:04 am
like the error message says, you are using CRM_Contact_Form_Task_Email as an array

$form['duration']['value'] should probably be $form->duration->value or $form->duration['value'] or similar...
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

aeszq

  • I post occasionally
  • **
  • Posts: 53
  • Karma: 0
Re: Adding 'duration' to Form:CRM_Contact_Form_Task_Email
April 14, 2013, 05:06:18 pm
Thanks, Michael. I have got the duration. It's $form->_elements[24]->_attributes['value'] .

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Adding 'duration' to Form:CRM_Contact_Form_Task_Email

This forum was archived on 2017-11-26.