Answers.Body: <p>Same accepted answer: <a href="https://stackoverflow.com/a/51280077/4329215">https://stackoverflow.com/a/51280077/4329215</a></p>
  
  <p>If you build a custom form, Civi need some fields for when a new Drupal user is created.</p>
  
  <p>1: Go to Civi profiles (/civicrm/admin/uf/group?reset=1) and select the desired profile you want to include in the form. I selected "Your registration form".
  Go to settings of the profile and select "used for => Drupal User Registration"
  In Advanced Settings check Account creation required</p>
  
  <p>2: In your custom form, implement the function: 'civicrm_form_user_register_form_alter'. </p>
  
  <pre><code>public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
      $validators = array(
          'file_validate_extensions' =&gt; array('jpg jpeg png'),
      );
      $form['uname'] = array(
          '#type' =&gt; 'textfield',
          '#placeholder' =&gt; t('Username*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
      $form['organisation'] = array(
          '#type' =&gt; 'textfield',
          '#placeholder' =&gt; t('Organisation name*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
      $form['password'] = array(
          '#type' =&gt; 'password_confirm',
          '#placeholder' =&gt; t('Password*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
      $form['name'] = array(
          '#type' =&gt; 'textfield',
          '#placeholder' =&gt; t('Full Name*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
      $form['email'] = array(
          '#type' =&gt; 'email',
          '#placeholder' =&gt; t('Email Address*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
  
      $form['street'] = array(
          '#type' =&gt; 'textfield',
          '#placeholder' =&gt; t('Street*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
      $form['nr'] = array(
          '#type' =&gt; 'textfield',
          '#placeholder' =&gt; t('Nr*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
      $form['zipcode'] = array(
          '#type' =&gt; 'textfield',
          '#placeholder' =&gt; t('Zipcode*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
      $form['city'] = array(
          '#type' =&gt; 'textfield',
          '#placeholder' =&gt; t('City*'),
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('class' =&gt; array('form-control')),
      );
  
      //This did the trick!
      if( function_exists('civicrm_form_user_register_form_alter') ) {
          civicrm_form_user_register_form_alter($form,$form_state,'customRegistration');
      }
  
      $form['actions'] = array('#type' =&gt; 'actions');
      $form['actions']['submit'] = array(
          '#type' =&gt; 'submit',
          '#value' =&gt; $this-&gt;t('Create'),
          '#attributes' =&gt; array('class' =&gt; array('btn', 'btn-cs', 'btn-outline')),
      );
      $form['#validate'][] = array($this, 'regValidate');
      return $form;
  } 
  </code></pre>
  
  <p>2: In your template, add the fields with the field name from the Civi function:                 </p>
  
  <pre><code>{{custom_registration_form.civicrm_profile_register}}
  </code></pre>
  
  <p>You find the name in /modules/civicrm-drupal/civicrm.module </p>
  
  <pre><code>$form['civicrm_profile_register'] = array(
      '#markup' =&gt; \Drupal\Core\Render\Markup::create($html),
      '#cache' =&gt; [
        'max-age' =&gt; 0,
      ],
  );
  </code></pre>
  
  <p>The fields from the profile will be included in your custom form and no problems with sessions key anymore.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-12T08:05:14.877Z
Answers.LastActivityDate: 2018-07-12T08:05:14.877Z
Answers.UserDisplayName: Joris
Body: <p>Since i installed CiviCRM on my Drupal site i can't save users anymore.</p>
  <blockquote>
  <p>Sorry, due to an error, we are unable to fulfill your request at the moment. You may want to contact your administrator or service provider with more details about what action you were performing when this occurred. We can't load the requested web page. This page requires cookies to be enabled in your browser settings. Please check this setting and enable cookies (if they are not enabled). Then try again. If this error persists, contact the site administrator for assistance.</p>
  <p>Site Administrators: This error may indicate that users are accessing this page using a domain or URL other than the configured Base URL. EXAMPLE: Base URL is <a href="http://example.org" rel="nofollow noreferrer">http://example.org</a>, but some users are accessing the page via <a href="http://www.example.org" rel="nofollow noreferrer">http://www.example.org</a> or a domain alias like <a href="http://myotherexample.org" rel="nofollow noreferrer">http://myotherexample.org</a>.</p>
  <p>Error type: Could not find a valid session key.</p>
  </blockquote>
  <p>Civi Resource urls for Civi is correct.
  It happens when i create a user with a form.</p>
  <p>Drupal: 8.4.0</p>
  <p>CiviCRM: 4.7.28</p>
  <p><strong>Edit:</strong>
  Because the original website was already built in Drupal 8 and it relies on some Drupal 8 features it will not be possible to switch to Drupal 7.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-09T18:18:40.453Z
Comments.Text: CiviCRM support for Drupal 8 is still fairly new and experimental. If you are just starting with CiviCRM then Drupal 7 is a far more tried and tested solution.
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-10T20:32:34.287Z
Comments.Text: try the Drupal channel on https://chat.civicrm.org/civicrm/channels/drupal
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-11T07:57:57.233Z
Comments.Text: Found it! Answer: https://stackoverflow.com/a/51280077/4329215 Thanks for the help
Comments.UserDisplayName: Joris
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-11T11:03:20.540Z
Comments.Text: @Joris could you please make that comment into an answer and mark it as correct to help others with the same problem?  Thanks!
Comments.UserDisplayName: Jon G - Megaphone Tech
Tags: <drupal><drupal-8><session>
Title: Could not find a valid session key
ThreadText: # Could not find a valid session key
  
  (Asked by: username_0 on 2018-07-09)
  
  Since i installed CiviCRM on my Drupal site i can't save users anymore.
  
  > Sorry, due to an error, we are unable to fulfill your request at the moment. You may want to contact your administrator or service provider with more details about what action you were performing when this occurred. We can't load the requested web page. This page requires cookies to be enabled in your browser settings. Please check this setting and enable cookies (if they are not enabled). Then try again. If this error persists, contact the site administrator for assistance.
  >
  > Site Administrators: This error may indicate that users are accessing this page using a domain or URL other than the configured Base URL. EXAMPLE: Base URL is <http://example.org>, but some users are accessing the page via <http://www.example.org> or a domain alias like <http://myotherexample.org>.
  >
  > Error type: Could not find a valid session key.
  
  Civi Resource urls for Civi is correct.
  It happens when i create a user with a form.
  
  Drupal: 8.4.0
  
  CiviCRM: 4.7.28
  
  **Edit:**
  Because the original website was already built in Drupal 8 and it relies on some Drupal 8 features it will not be possible to switch to Drupal 7.
  
  **Tags:** drupal, drupal-8, session
  
  > **Comments:**
  > **username_1**: CiviCRM support for Drupal 8 is still fairly new and experimental. If you are just starting with CiviCRM then Drupal 7 is a far more tried and tested solution.  
  > **username_2**: try the Drupal channel on https://chat.civicrm.org/civicrm/channels/drupal  
  > **username_3**: Found it! Answer: https://stackoverflow.com/a/51280077/4329215 Thanks for the help  
  > **username_4**: @username_3 could you please make that comment into an answer and mark it as correct to help others with the same problem?  Thanks!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2018-07-12. Score: 1
  
  Same accepted answer: https://stackoverflow.com/a/51280077/4329215
  If you build a custom form, Civi need some fields for when a new Drupal user is created.
  1: Go to Civi profiles (/civicrm/admin/uf/group?reset=1) and select the desired profile you want to include in the form. I selected "Your registration form".
  Go to settings of the profile and select "used for => Drupal User Registration"
  In Advanced Settings check Account creation required
  2: In your custom form, implement the function: 'civicrm_form_user_register_form_alter'. 
  public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
      $validators = array(
          'file_validate_extensions' => array('jpg jpeg png'),
      );
      $form['uname'] = array(
          '#type' => 'textfield',
          '#placeholder' => t('Username*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
      $form['organisation'] = array(
          '#type' => 'textfield',
          '#placeholder' => t('Organisation name*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
      $form['password'] = array(
          '#type' => 'password_confirm',
          '#placeholder' => t('Password*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
      $form['name'] = array(
          '#type' => 'textfield',
          '#placeholder' => t('Full Name*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
      $form['email'] = array(
          '#type' => 'email',
          '#placeholder' => t('Email Address*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
  
      $form['street'] = array(
          '#type' => 'textfield',
          '#placeholder' => t('Street*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
      $form['nr'] = array(
          '#type' => 'textfield',
          '#placeholder' => t('Nr*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
      $form['zipcode'] = array(
          '#type' => 'textfield',
          '#placeholder' => t('Zipcode*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
      $form['city'] = array(
          '#type' => 'textfield',
          '#placeholder' => t('City*'),
          '#required' => TRUE,
          '#attributes' => array('class' => array('form-control')),
      );
  
      //This did the trick!
      if( function_exists('civicrm_form_user_register_form_alter') ) {
          civicrm_form_user_register_form_alter($form,$form_state,'customRegistration');
      }
  
      $form['actions'] = array('#type' => 'actions');
      $form['actions']['submit'] = array(
          '#type' => 'submit',
          '#value' => $this->t('Create'),
          '#attributes' => array('class' => array('btn', 'btn-cs', 'btn-outline')),
      );
      $form['#validate'][] = array($this, 'regValidate');
      return $form;
  } 
  
  2: In your template, add the fields with the field name from the Civi function:                 
  {{custom_registration_form.civicrm_profile_register}}
  
  You find the name in /modules/civicrm-drupal/civicrm.module 
  $form['civicrm_profile_register'] = array(
      '#markup' => \Drupal\Core\Render\Markup::create($html),
      '#cache' => [
        'max-age' => 0,
      ],
  );
  
  The fields from the profile will be included in your custom form and no problems with sessions key anymore.
  
  
  ---
  
  