I use this code in my form ( buildForm(array $form, FormStateInterface $form_state) ) :
<?php
namespace Drupal\test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\SessionManager;
use Symfony\Component\HttpFoundation\Response;
class TestForm extends FormBase {
public function getFormId() {
return 'TESTOLDTONEW';
}
public function buildForm(array $form, FormStateInterface $form_state) {
\Drupal::service('page_cache_kill_switch')->trigger();
$a['ad_mail'] = [
'#type' => 'email',
'#title' => t('Email ID:'),
'#required' => TRUE,
];
$b['total'] = [
'#type' => 'hidden',
'#attributes' => [
'id' => 'actionsubmitid',
],
'#value' => '0',
];
$c['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Finalize the purchase'),
'#button_type' => 'primary',
];
$test= [
'#theme' => 'test',
'#a' => $a,
'#b' => $b,
'#c' => $c,
];
return $test;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect('test.new');
}
}
Now I want redirect to a machin name ( for example "test.new" ) that create in routing.yml file . I use $form_state->setRedirect('test.new');
in "submitForm(array &$form, FormStateInterface $form_state)" but not work .
EDITED :
.routing.yml
test.old:
path: '/test/old'
defaults:
_form: '\Drupal\bpay\Form\TestoldForm'
requirements:
_permission: 'access content'
test.new:
path: '/test/new'
defaults:
_controller: '\Drupal\bpay\Controller\TestnewController::new'
requirements:
_permission: 'access content'