How could I get the participant ID and the corresponding contact ID on the event registration thank-you page? E.g. is there a field (or piece of code) I can insert in /templates/CRM/Event/Form/Registration/DisplayProfile.tpl ?

For participant ID I tried the following but to no avail:

<div class="participant-id hidden">{$participant.id}</div>

Thank you for any tips

  • 2
    you can try inserting {debug} at any line in the file and check the variables that are populating for the template file. Commented Apr 8, 2018 at 6:18
  • Thank you for the tip, @jitendra-fuzion, I did what you suggested, and the only helpful variable I see is an array {$participantIDs} ... we only allow one participant so how could I grab the first (and only) item in the array?
    – MtnPavlas
    Commented Apr 9, 2018 at 3:17
  • OK - found a good-enough answer for now - posting it below; thank you again for the tip
    – MtnPavlas
    Commented Apr 9, 2018 at 3:25

2 Answers 2


the following did the trick - works in this situation well enough as we only allow registering one participant:


The above grabs the participant ID of the first (and only in our case) participant

  • I found a PHP-only approach to get the participant_id. @ me if interested.
    – dsmith63
    Commented Jan 24, 2022 at 22:16
  • @dsmith63 sure thing - please do share. Thanks!
    – MtnPavlas
    Commented Feb 9, 2022 at 17:06

The participant_id can be accessed on the event registration thank you page in two different ways -- by using Smarty template variables when the user is logged in or by using session variables when the user is anonymous. Both approaches work when used inside the "civicrmBuildForm" hook.

1) User logged in

add_action( 'civicrm_buildForm', 'getParticipantId' );

function getParticipantId() {
    $template = (array) CRM_Core_Smarty::singleton();
    $event = $template['_tpl_vars']['event'];

    $participant = civicrm_api3('Participant', 'getsingle', [
        'sequential' => 1,
        'contact_id' => "user_contact_id",
        'event_id' => $event['id'],

    echo $participant['id'];

2) Anonymous user

add_action( 'civicrm_buildForm', 'getParticipantId' );

function getCrmFromSession($session) {
    if (!empty($session)) {
        $seshAry = (array) $session;
        $seshKey = array_keys($seshAry)[1];
        $CiviCRM = json_decode(json_encode($seshAry[$seshKey]), true)['CiviCRM'];

        if ( !empty($CiviCRM['CRM_Utils_Recent']) && isset($CiviCRM['CRM_Utils_Recent'][0]['id']) ) {
            $CiviCRM['participant_id'] = $CiviCRM['CRM_Utils_Recent'][0]['id'];

        return $CiviCRM;
    } else {
        return array();

function getParticipantId() {
    $CiviCRM = getCrmFromSession(CRM_Core_Session::singleton());

    echo $CiviCRM['participant_id'];
  • I appended a template to the Thank You template with the data related to participant_id.
  • In my case, the BuildForm hook lives in my theme's functions.php file.
  • @MtnPavlas, hope this helps.
    – dsmith63
    Commented Feb 10, 2022 at 18:46
  • thank you for the code, @dsmith63 - super helpful
    – MtnPavlas
    Commented Feb 11, 2022 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.