Conditionally register a user based on fields I have a Drupal 8 User registration form that has several text fields to gather information about the user.

I'd like to write a custom hook that examines the values in those fields and then either proceeds with the registration or 'cancels' it, like perhaps redirecting to a static page or displaying some static content.

What are the hooks I need to make this happen?  Do I alter the form?  Or do I hook an entity_presave function?

What do I need to do to cancel the default form processing or default entity presave/save routines?

thanks,
Forms have a validate and submit function(s). Submit never runs unless all validation passes.

So all you have to do is add a custom validation

/*
 * Implements hook_form_FORM_ID_alter
 */
function mymodule_form_user_register_form_alter(&amp;$form, FormStateInterface $form_state) {

  $form['#validate'][] = 'mymodule_registration_validate';

}

/*
 * Custom Validation
 */
function mymodule_registration_validate(&amp;$form, FormStateInterface $form_state) {

  $field_name = $form_state-&gt;getValue('field_name'); // Gets the value entered by the user
  // Note: depending on your field type &amp; settings sometimes this value is an
  // array, so you may have to keep drilling down.
  if($field_name != 'Hello World') { // perform check
    $message = t('Only Hello World is allowed'); // message to display
    $form_state-&gt;setErrorByName('field_name', $message); // set error
  }

}


$form_state-&gt;setErrorByName will display an error message and highlight the offending field in red.

If  you want to redirect use $form_state-&gt;setRedirectUrl($url);