Answers.Body: <p>The problem is that your hook is executing unconditionally on every form. To target just the contribution form, the first line inside your function should be <code>if ($formName == 'CRM_Contribute_Form_Contribution_Main') {</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-05T16:10:01.750Z
Answers.LastActivityDate: 2015-07-05T16:10:01.750Z
Answers.UserDisplayName: Coleman
Body: <p>I have a custom function written to show the name of the contribution page that a PCP is a part of. After some help from the community, I got it working, hooray! 
  <a href="https://civicrm.stackexchange.com/questions/2856/trying-to-write-a-hook-to-add-contribution-page-name-to-main-tpl-im-super-close">Trying to write a hook to add contribution page name to Main.tpl I&#39;m super close</a></p>
  
  <p>But on my event registration links (not contribution pages, oddly enough) or PCP creation links - I get the following error 'CiviCRM_API3_Exception: "Expected one ContributionPage but found 25"' (I have a total of 25 contribution pages set up so I can see why it says it finds 25 but why it's looking in the first place I'm not sure.</p>
  
  <p>Here is the final code I'm using</p>
  
  <pre><code>function wordpress_civicrm_buildForm($formName, &amp;$form) {
      $config = CRM_Core_Config::singleton();
      if ( $config-&gt;userFrameworkFrontend ) {
  
            $page = civicrm_api3('contribution_page', 'getsingle', array(
              'id' =&gt; $form-&gt;_id,
              'check_permissions' =&gt; FALSE,
              'return' =&gt; 'title',
            ));
            $form-&gt;assign('cPageName', $page['title']);
  
      }
  }
  </code></pre>
  
  <p>Ideas?</p>
  
Tags: <hooks><pcp><personal-campaign-pages>
Title: Custom Hook causes for a PCP problems on event registration page
ThreadText: # Custom Hook causes for a PCP problems on event registration page
  
  (Asked by: username_0 on 2015-07-05)
  
  I have a custom function written to show the name of the contribution page that a PCP is a part of. After some help from the community, I got it working, hooray! 
  Trying to write a hook to add contribution page name to Main.tpl I'm super close
  But on my event registration links (not contribution pages, oddly enough) or PCP creation links - I get the following error 'CiviCRM_API3_Exception: "Expected one ContributionPage but found 25"' (I have a total of 25 contribution pages set up so I can see why it says it finds 25 but why it's looking in the first place I'm not sure.
  Here is the final code I'm using
  function wordpress_civicrm_buildForm($formName, &$form) {
      $config = CRM_Core_Config::singleton();
      if ( $config->userFrameworkFrontend ) {
  
            $page = civicrm_api3('contribution_page', 'getsingle', array(
              'id' => $form->_id,
              'check_permissions' => FALSE,
              'return' => 'title',
            ));
            $form->assign('cPageName', $page['title']);
  
      }
  }
  
  Ideas?
  
  **Tags:** hooks, pcp, personal-campaign-pages
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-07-05. Score: 0 | Accepted answer
  
  The problem is that your hook is executing unconditionally on every form. To target just the contribution form, the first line inside your function should be `if ($formName == 'CRM_Contribute_Form_Contribution_Main') {`.
  
  
  ---
  
  