Aug 22, 2017 in Drupal 8

A snippet with submitForm to redirect your form to another page and pass a variable:

// inside your custom form, place this snippet:
    public function buildForm(array $form, FormStateInterface $form_state) {
        $form['email'] = array(
            '#type' => 'email',
            '#title' => t('Your e-mail address'),
            '#required' => TRUE,
        );

        $form['actions']['#type'] = 'actions';
        $form['actions']['submit'] = array(
            '#type' => 'submit',
            '#value' => $this->t('Submit'),

        );
        return $form;
    }    

    public function submitForm(array &$form, FormStateInterface $form_state) {
        $input = $form_state->getValue('email');
        $params['query'] = [
            'e' => $input,
        ];
        $form_state->setRedirectUrl(Url::fromUri('internal:' . 'YOUR_ROUTE', $params));
    }