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) »
  • hook buildForm error upon clicking "add" link
Pages: [1]

Author Topic: hook buildForm error upon clicking "add" link  (Read 1653 times)

JoopSJ

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 2
hook buildForm error upon clicking "add" link
September 25, 2009, 06:06:30 pm
I'm using civicrm_buildform hook to freeze the external_identifier since I don't want its value to be changed when a contact is edited.

I use the following code, which works good.
Code: [Select]
if ($formName == "CRM_Contact_Form_Contact") {
$elem = $form->getElement('external_identifier');
$elem->freeze();
}

But when I select an "add" link (f.i. to add an email address) the following error happens:

Code: [Select]
[message] => QuickForm Error: nonexistent html element
    [mode] => 16
    [debug_info] => Element 'external_identifier' does not exist in HTML_QuickForm::getElement()
    [type] => HTML_QuickForm_Error
    [user_info] => Element 'external_identifier' does not exist in HTML_QuickForm::getElement()
    [to_string] => [html_quickform_error: message="nonexistent html element" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="QuickForm Error: " info="Element 'external_identifier' does not exist in HTML_QuickForm::getElement()"]
)

It looks the buildform hook is fired again by the "add" link and that the form element cannot be found.
Thanks,
Joop

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: hook buildForm error upon clicking "add" link
September 25, 2009, 06:44:15 pm

hey joop:

how about using the following piece of code:

Code: [Select]
if ($formName == "CRM_Contact_Form_Contact" &&
            $form->elementExists( 'external_identifier' ) ) {
$elem = $form->getElement('external_identifier');
$elem->freeze();
}

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

JoopSJ

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 2
Re: hook buildForm error upon clicking "add" link
September 26, 2009, 06:55:19 pm
Hello Lobo,
Thanks, testing whether the element is there solved it.
Regards, Joop

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: hook buildForm error upon clicking "add" link
October 03, 2012, 08:17:47 pm
Would something have changed between 4.1.2 and 4.2.2 to cause this problem to crop up in a couple of places when it didn't appear otherwise?  I'm freezing the "register multiple participants" field in Event Online Registration configuration, and then when I try and add a profile (a link further down the page that uses AJAX), it throws an element not found error.  This did not happen in 4.1.2.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • hook buildForm error upon clicking "add" link

This forum was archived on 2017-11-26.