Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save henideepak/ba020954b0e91341a247d39086442984 to your computer and use it in GitHub Desktop.
Save henideepak/ba020954b0e91341a247d39086442984 to your computer and use it in GitHub Desktop.
Drupal 8 Registration form and redirect Home page after show custom message.
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Messenger\MessengerInterface;
/**
* Implements hook_form_FORM_ID_alter().
*/
function MODULE_NAME_form_alter( array &$form, FormStateInterface $form_state, $form_id ) {
if ($form_id == 'user_register_form' ) {
$form['actions']['submit']['#submit'][] = '_redirect_handler';
}
}
function _redirect_handler($form, FormStateInterface $form_state) {
// $dest_url = "/";
// $url = Url::fromUri('internal:' . $dest_url);
// $form_state->setRedirectUrl( $url );
$url = Url::fromUri('internal:/');
$response = new RedirectResponse($url->toString());
$response->send();
$message = 'A welcome message with further instructions has been sent to your email address. If you have not seen it check your spam folder.';
\Drupal::messenger()->addStatus($message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment