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) »
  • How can hook into the contacts editing page?
Pages: [1]

Author Topic: How can hook into the contacts editing page?  (Read 620 times)

rogical

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 1
  • CiviCRM version: 4.2
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3
How can hook into the contacts editing page?
October 26, 2012, 06:23:28 am
I want to make same validating or redirecting on contacts editing page, I want some kinds of contacts doesn't allow specific users to edit.  Is there a hook to do this? Thanks!

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: How can hook into the contacts editing page?
October 26, 2012, 07:00:50 am
Yes there is, you will probably want to use the validate or validateForm hook, depending on the version of CiviCRM you are using. Check http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

rogical

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 1
  • CiviCRM version: 4.2
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3
Re: How can hook into the contacts editing page?
October 27, 2012, 05:25:55 am
I've read that page, there's an example, there's no form_id on the contact add page, How can I know the form name?  Thanks

function MODULENAME_civicrm_validateForm( $formName, &$fields, &$files, &$form, &$errors ) {
    // sample implementation
    if ( $formName == 'CRM_Contact_Form_Contact' ) {
       // ensure that external identifier is present and valid
       $externalID = CRM_Utils_Array::value( 'external_identifier', $fields );
       if ( ! $externalID ) {
          $errors['external_identifier'] = ts( 'External Identifier is a required field' );
       } else if ( ! myCustomValidatorFunction( $externalID ) ) {
          $errors['external_identifier'] = ts( 'External Identifier is not valid' );
       }
    }
    return;
 
}

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: How can hook into the contacts editing page?
October 27, 2012, 09:56:12 am
Not sure I understand what you are trying to do, but you will find that this chapter describes the concepts and should let you find what you are looking for

http://book.civicrm.org/developer/current/techniques/hooks/
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: How can hook into the contacts editing page?
October 29, 2012, 02:10:24 am
Hey Rogical,

Quote
How can I know the form name?

The form name == the class that builds the form - the one that extends CiviCRM's base form class.

The buildForm hook looks quite similar and is called on every form load so what I normally do is add a print_r($formName); to (the beginning) of a pre-process hook and it should print it on the screen somewhere.

The other thing you can do is inspect the template since that normally prints the path of the template that is used, which in the vast majority of cases, has a corresponding php file which contains the form class.

Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How can hook into the contacts editing page?

This forum was archived on 2017-11-26.