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);
$response->send();
}
or use this method:
$url = Url::fromUri('internal:' . 'YOUR_ROUTE', $params);
$form_state->setRedirectUrl($url);