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 Profiles (Moderator: Dave Greenberg) »
  • Trying to Implement Hidden Profile Fields Using Hooks and Having Problems
Pages: [1]

Author Topic: Trying to Implement Hidden Profile Fields Using Hooks and Having Problems  (Read 695 times)

dwfriederichs

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 1
Trying to Implement Hidden Profile Fields Using Hooks and Having Problems
August 15, 2012, 03:42:12 pm
I'm a novice at this area of Civi so I appreciate any help.  Running Civi 4.0.6 on Joomla 1.7.1. 

I'm trying to implement hidden fields on one of my CiviCRM profiles.  Looking through blogs and the forum, it seemed hooks were the way to do it.  I got some sample code and have tried to implement it without success.

I created a file with the below code named civicrmHooks.php and put it into a directory called /administrator/com_civicrm/civicrm/hooks, and set the custom PHP directory in Civi to look in that directory.  The code is as follows:

function joomla_civicrm_buildForm( $formName, &$form ) {
  // for the MentorOne respectful decline forms, this sets the two fields below as hidden and sets them to negative values
  if ( $formName == 'CRM_Profile_Form_Edit' ) {
         // add hidden element for every profile form with name as 'custom_element_name' and value as 'element_value'
       $form->addElement('hidden', 'Alumni One-on-One Interest',   'Not Interested in the Mentoring Program' );
       $form->addElement('hidden', 'Undergraduate One-on-One Interest',   'Not Interested in the Mentoring Program' );
    }
 }

"Alumni One-on-One Interest" and "Undergraduate One-on-One Interest" are the two fields whose values I'm trying to set.  "Not Interested in the Mentoring Program" is what the fields should be set to.  The profile where I want these hidden fields placed is named "MentorOne Respectful Decline".

When I complete the profile, the visible fields update correctly but these hidden ones do not. 

Any help the group can provide would be appreciated.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Trying to Implement Hidden Profile Fields Using Hooks and Having Problems
August 15, 2012, 11:19:16 pm
Not sure if this makes the difference, but I tend to use this to set the default values in the form:
Code: [Select]
$form->addElement('hidden', 'fieldname1');
$form->addElement('hidden', 'fieldname2');
$defaults = array('fieldname1' => $value1, 'fieldname2' => $value2);
$form->setDefaults( $defaults );
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Trying to Implement Hidden Profile Fields Using Hooks and Having Problems

This forum was archived on 2017-11-26.