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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Trying to get query string parms inside civicrm_buildForm hook
Pages: [1]

Author Topic: Trying to get query string parms inside civicrm_buildForm hook  (Read 1430 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Trying to get query string parms inside civicrm_buildForm hook
August 21, 2010, 05:16:35 pm
I am implementing the hook "mymodule_civicrm_buildForm" , which is checking that the form is ''CRM_Profile_Form_Edit' and the profile id is 8. ( That part is working fine ).    I am using the following URL to reach my profile:  
http://devd.mygroup.org/civicrm/profile/edit?reset=1&gid=8&pid=51&eid=3    

Note that the last 2 variables in the query string are a participant id ( pid=51 ) and an event id (eid=3 ). I am struggling to access those values in my hook.  

How can I  get those extra query string values?  The URL is built in a custom .tpl file for the user dashboard that will allow a person to mark themselves "attended"  after an event.

Thanks,
Sarah
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Trying to get query string parms inside civicrm_buildForm hook
August 21, 2010, 05:34:14 pm
Hi Sarah,

Those values should be available to you in $_GET['pid'] and $_GET['eid'].  You could access them directly with that syntax, but this syntax gives you a chance to set a default value:

$myPid = CRM_Utils_Array::value('pid', $_GET, '0');  // setting 0 as default if 'pid' is not found
$myEid = CRM_Utils_Array::value('eid', $_GET, '0');  // setting 0 as default if 'pid' is not found

I notice in existing CiviCRM code, the CRM_Utils_Array::value() is used routinely, even when no default is specified, and as far as I know the former syntax is never used.  I'm guessing that's for the sake of consistency more than anything else.

- TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Trying to get query string parms inside civicrm_buildForm hook
August 21, 2010, 09:16:07 pm
The second code sample did the trick, Thanks
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Trying to get query string parms inside civicrm_buildForm hook

This forum was archived on 2017-11-26.