Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

Code snippet that can be used to redirect your custom form to another page and pass a variable Drupal 8.

public function buildForm(array $form, FormStateInterface $form_state, $arg = NULL)
  $form['email'] = array(
    '#type' => 'email',
    '#title' => t('Email'),
    '#required' => TRUE,
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  return $form;

public function submitForm(array &$form, FormStateInterface $form_state)
  $path = \Drupal\Core\Url::fromRoute('your.routename', ['email' => $form_state->getValue('email')])->toString();
  $response = new RedirectResponse($path);

or use this method:


$url = Url::fromUri('internal:' . 'YOUR_ROUTE', $params);




Add new comment

Restricted HTML


Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon