11

This is my first question on a stackexchange-like website, so bare with if I fail to mention something important about my question.

The situation

At the moment, I’m working on my very first CiviCRM-system in combination with Wordpress. My client currently uses CiviCRM in combination with Drupal, so I migrated the CiviCRM-database. The system mainly focusses on CiviEvents. The below is tested while not logged in as a Wordpress-user.

The problem

The problem I’m facing is that when I want to subscribe on a CiviEvent with the standard register-form provided by Civi, I end up getting redirected to this URL and this error is presented:


Redirected to:

http://localhost/DNN/?page=CiviCRM&q=civicrm%2Fevent%2Fregister&_qf_ThankYou_display=true&qfKey=74c1a421f35974b95728fb7b661a9d79_1904

Presented error: Could not find valid value for id

enter image description here


The registration does come through though. So apparently, saving the registration is going well.

When I debugged this issue I found that this error is thrown when the class CRM_Event_StateMachine_Registration is instantiated and the following is executed:

$id = CRM_Utils_Request::retrieve('id', 'Positive', $controller, TRUE);

(file: CRM/Event/StateMachine/Registration.php)

The method retrieve tries to extract the value for id from either $_GET, $_POST or $_REQUEST. In this case, he tries to extract it from $_REQUEST. The contents of $_REQUEST is:

Array
(
    [page] => CiviCRM
    [q] => civicrm/event/register
    [page_id] => 6
    [noheader] => 1
    [qfKey] => ecb991dac9477d393014910b1472fb2b_9259
    [entryURL] => http://localhost/DNN/?page=CiviCRM&q=civicrm/event/register&page_id=6&page=CiviCRM&id=506&reset=1
    [scriptFee] => 
    [scriptArray] => 
    [_qf_default] => Register:upload
    [MAX_FILE_SIZE] => 33554432
    [phone-Primary-2] => 0612345678
    [current_employer] => Test-employer
    [first_name] => Test-firstname
    [last_name] => Test-lastname
    [street_address-2] => Test-street-address
    [postal_code-2] => Test-postal-code
    [city-2] => Test-city
    [participant_source] => 
    [email-Primary] => [email protected]
)

As you can see, id is indeed missing. So I think the real question is: why isn’t Civi sending the id in this request? It is a standard, by Civi provided functionality after all.

Does anyone have any idea why I’m getting this message?

For completeness, this the backtrace from the point this error is thrown:

0 - Request.php - Line: 95 - dnn_backtrace () - /DNN/wp-content/plugins/civicrm/civicrm/CRM/Utils/Request.php
1 - Registration.php - Line: 52 - retrieve () - /DNN/wp-content/plugins/civicrm/civicrm/CRM/Event/StateMachine/Registration.php
2 - Registration.php - Line: 47 - __construct () - /DNN/wp-content/plugins/civicrm/civicrm/CRM/Event/Controller/Registration.php
3 - Invoke.php - Line: 307 - __construct () - /DNN/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php
4 - Invoke.php - Line: 86 - runItem () - /DNN/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php
5 - Invoke.php - Line: 54 - _invoke () - /DNN/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php
6 - civicrm.php - Line: 1189 - invoke () - /DNN/wp-content/plugins/civicrm/civicrm.php
7 - civicrm.basepage.php - Line: 134 - invoke () - /DNN/wp-content/plugins/civicrm/includes/civicrm.basepage.php
8 - - Line: - basepage_handler () - 
9 - plugin.php - Line: 571 - call_user_func_array () - /DNN/wp-includes/plugin.php
10 - class-wp.php - Line: 622 - do_action_ref_array () - /DNN/wp-includes/class-wp.php
11 - functions.php - Line: 877 - main () - /DNN/wp-includes/functions.php
12 - wp-blog-header.php - Line: 14 - wp () - /DNN/wp-blog-header.php
13 - index.php - Line: 19 - require () - /DNN/index.php

EDIT

I forgot all about the error-logging Civi does. This is the error that is logged after registration.

Aug 18 14:31:54  [info] $Fatal Error Details = Array
(
    [message] => Could not find valid value for id
    [code] => 
)


Aug 18 14:31:54  [info] $backTrace = #0 /DNN/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(363): CRM_Core_Error::backtrace("backTrace", TRUE)
#1 /DNN/wp-content/plugins/civicrm/civicrm/CRM/Utils/Request.php(96): CRM_Core_Error::fatal("Could not find valid value for id")
#2 /DNN/wp-content/plugins/civicrm/civicrm/CRM/Event/StateMachine/Registration.php(52): CRM_Utils_Request::retrieve("id", "Positive", Object(CRM_Event_Controller_Registration), TRUE)
#3 /DNN/wp-content/plugins/civicrm/civicrm/CRM/Event/Controller/Registration.php(47): CRM_Event_StateMachine_Registration->__construct(Object(CRM_Event_Controller_Registration), TRUE)
#4 /DNN/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(307): CRM_Event_Controller_Registration->__construct("Event Registration", TRUE, "null", NULL, "false")
#5 /DNN/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(86): CRM_Core_Invoke::runItem((Array:15))
#6 /DNN/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(54): CRM_Core_Invoke::_invoke((Array:3))
#7 /DNN/wp-content/plugins/civicrm/civicrm.php(1189): CRM_Core_Invoke::invoke((Array:3))
#8 /DNN/wp-content/plugins/civicrm/includes/civicrm.basepage.php(134): CiviCRM_For_WordPress->invoke()
#9 [internal function](): CiviCRM_For_WordPress_Basepage->basepage_handler(Object(WP))
#10 /DNN/wp-includes/plugin.php(571): call_user_func_array((Array:2), (Array:1))
#11 /DNN/wp-includes/class-wp.php(622): do_action_ref_array("wp", (Array:1))
#12 /DNN/wp-includes/functions.php(877): WP->main("")
#13 /DNN/wp-blog-header.php(14): wp()
#14 /DNN/index.php(19): require("/DNN/wp-blog-header.php")
#15 {main}
10
  • What's your exact version? I had a client contact me today with the exact same symptoms when trying to register for a new event. They're on Civi 4.6.0 with Wordpress 4.2.4.
    – Nicholai
    Aug 18, 2015 at 23:59
  • I'm using Civi 4.6.4 with Wordpress 4.2.2
    – user825
    Aug 19, 2015 at 9:27
  • Is this a free or paid event? Perhaps we can narrow it down to a payment processor (or lack thereof)?
    – Nicholai
    Aug 19, 2015 at 12:46
  • Have the same issue on Drupal 7 with Civi 4.6.8 Can't seem to figure this out. This is a paid event using a price set
    – Yossi
    Sep 2, 2015 at 5:39
  • 1
    I'm having the same issue (WP4.4.1, Civi4.6.10, Stripe ext 1.9.1). The extension resource url is set, and the WP Base Page using the default civicrm (which is there with the 'Do not delete this page' warning). Still getting the "Could not find valid value for ID" error. Since I'm emailing confirmation of registration, is there a way to disable the final thankyou page / redirect so that folks don't see the spurious error? I'm taking payments so it's causing more than the usual consternation. Jan 22, 2016 at 10:23

7 Answers 7

11

This is a bit of "surprise" but essentially for 4.6 and beyond Civi event registration for Wordpress won't work unless you either 1) use a 'base page' or a 2) WP short code

Solution #1 has two steps.

  1. create a WP page with the 'civicrm' permalink
  2. set a 'base page' within CiviCRM

See attached images.

new page

base page

2
  • Thanks for your answer! Just checked and apparently I don't have a base page set. So will definitely try that, but at this point I already downgraded to Civi 4.4.19 (LTS), since on this version the registration works. I'm hoping to upgrade somewhere in the near future. Thanks!
    – user825
    Sep 22, 2015 at 7:53
  • 1
    We finally made time to test this answer (since we were upgrading Civi) and it works! It is worth mentioning though that my initial question was about Civi 4.6.4 and I tested this answer when I was already updated to 4.7.6.
    – user825
    Apr 24, 2016 at 19:22
7

I stumbled on this issue on CiviCRM 5.44 sites on WordPress, and the issue was that the site did not have "Clean URLs" enabled, since it was using an old civicrm.settings.php.

Make sure that the civicrm.settings.php has this bit of code:

  if (!defined('CIVICRM_CLEANURL')) {
    if ( function_exists('variable_get') && variable_get('clean_url', '0') != '0') {
      define('CIVICRM_CLEANURL', 1 );
    }
    elseif ( function_exists('config_get') && config_get('system.core', 'clean_url') != 0) {
      define('CIVICRM_CLEANURL', 1 );
    }
    elseif( function_exists('get_option') && get_option('permalink_structure') != '' ) {
      define('CIVICRM_CLEANURL', 1 );
    }
    else {
      define('CIVICRM_CLEANURL', 0);
    }
  }

and then in WordPress permalink settings, make sure that it uses the "post name" to form permalinks (this might not be strictly necessary according to docs, but I found that it helps), and save the permalinks setting form, so that the permalink cache is flushed.

Finally, Event Registration pages will be accessible using URLs that look like:

https://example.org/civicrm/event/register/?id=123&reset=1

3

I was having a similar problem. I noticed the base url for WordPress was not set.

If you haven't set that, try setting that in Administer > CMS Database Integration and let us know if that fixed your issue.

Make sure the event is not the home page, that seems to cause problems with the base url.

2
  • It's called a "base page" actually. And the second step of this configuration is to actually create a WP page with this URL. For instance if your base page is "civi" your WP page must have the permalink of "civi" as well. See my post below for screenshots Sep 21, 2015 at 21:01
  • I misunderstood your answer, Sanjay Jain. I noticed it was set to the base URL of the website, so I thought that was okay. CiviTeacher cleared this up now and will try this solution! Thanks for your help!
    – user825
    Sep 22, 2015 at 7:59
1

On 4.7.9 + WP 4.5.3 I had this problem.

I have a paid event, with PayPal as payment processor, but also the Pay Later option is enabled.

Registrations proceed fine when paid with PayPal. I only get this error when a user ticks the Pay Later option.

I tried using a WP shortcode as CiviTeacher mentioned but that did not work. I had to set a Base Page - i.e., Administer | System Settings | CMS Database Integration could not be blank.

It doesn't have to be civicrm, it can be anything you want. You can use http://www.domain.org/event or something similar.

Then you have to create a Page in WordPress with this URL as the permalink. I then put the event shortcode on this page and it works great!

In my case I then set up an intro page at http://www.domain.org/ with a "Registration" link to http://www.domain.org/event.

1

If you upgrade from CiviCRM < 4.6, and have a WP frontend with links to Civicrm pages (e.g. an event calendar) that are full URLs, you'll need to edit those links: from 'http://example.com/?page=Civicrm...' to 'http://example.com/civicrm/?page=Civicrm...' to get the basepage.

1

I had this problem intermittently for some time when embedding event registration forms using a Wordpress shortcode. It has to do with page caching. CiviCRM parses the shortcode to capture the event ID and adds the id value to the global $_GET object. If the page is loaded from cache (usually when the back/forward button is pressed) the code that parses the shortcode does not run, and the event ID is not added to $_GET.

I was able to fix this issue by making a page cache exception with the caching plugin I'm using.

I think this behavior is essentially a bug and CiviCRM should output a hidden form variable with the event ID so that it still gets passed to the "Thank You" page if the registration form is loaded from cache.

This is where Civi parses the shortcode and assigns the environment vars: civicrm/includes/civicrm.shortcode.php:

// Preprocess shortcode attributes.
$args = $this->preprocess_atts($atts);

// Sanity check for improperly constructed shortcode.
if ($args === FALSE) {
  return '<p>' . __('Do not know how to handle this shortcode.', 'civicrm') . '</p>';
}

// invoke() requires environment variables to be set.
foreach ($args as $key => $value) {
  if ($value !== NULL) {
    set_query_var($key, $value);
    $_REQUEST[$key] = $_GET[$key] = $value;
  }
}

Here are 3 solutions that are verified working:

1) Use the "civicrm_buildForm" hook with a template Region to add a custom template to Event Registration and Contribution forms (recommended).

add_action( 'civicrm_buildForm', 'onBeforeFormBuilt' );

function onBeforeFormBuilt($formName) {
    $formSubmitMap = array(
        'CRM_Contribute_Form_Contribution_Main' => array('contribution-main-not-you-block', 'CRM/Custom/ContributionFormId.tpl'),
        'CRM_Event_Form_Registration_Register' => array('event-register-not-you-block', 'CRM/Custom/EventFormId.tpl')
    );
    
    if ( in_array($formName, array_keys($formSubmitMap)) ) {
        $formType = $formSubmitMap[$formName];
    
        CRM_Core_Region::instance($formType[0])->add(array(
            'template' => $formType[1],
        ));
    }
}

Contents of ContributionFormId.tpl:

<input type="hidden" name="id" value="{$contributionPageID}">

Contents of EventFormId.tpl:

<input type="hidden" name="id" value="{$event.id}">

2) Modify core code (not recommended).

If you want to allow your registration page to be cached and you're willing to modify Core code, here is a quick hack: civicrm/CRM/Core/Form.php (after qfKey section):

if (isset($_REQUEST['id'])) {
    $this->addElement('hidden', 'id', $_REQUEST['id']); }
}

3) Use Javascript to perform a hard reload when the page is loaded from cache (not recommended).

function purgeCache() {
    if ( function_exists('has_tag') && function_exists('get_the_id') && has_tag('logged-in-no-cache', get_the_id()) ) {
        // If this page has a tag "no-cache", force browser to NOT load from cache
        $currQs = parsedUrl()['query'];

        echo "
        <script>
            // Back buttom was pressed prior to loading this page
            if (window.performance) {
                if (window.performance.navigation.type === 2) {
                    location.reload(true);
                }
            // Use History to force cache purge
            } else if (window.history && history.pushState) {
                history.pushState('page-load', '', '" . (!empty($currQs) ? $currQs . '&' : '?') . "w3tc_flush_post&post_id=" . get_the_id() . "');
            }
        </script>";
    }
}

I haven't verified the history.pushState approach, but it should work OK.

0
0

I'm not sure of the cause, but I have a workaround. I'm guessing that you are using the direct link that Civi tells you to copy and paste from the event management page. Using that gives me the error too. However I created a WP page, embedded the event registration as a shortcode, and made it through registration and confirmation without errors.

1
  • But when you embed the registration form with a shortcode, you have to specify the event to show the form for, right? To give a little more insight, I created a custom shortcode that lists CiviEvents. When you click on one of these events, you'll go to the event detailpage, which is the default page from Civi that I overwrite in the custom templates folder. On this page I use the URL to the registration page that is also used in the default page from Civi.
    – user825
    Aug 19, 2015 at 9:29

Your Answer

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

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