I have a form :
function buildForm(array $form, FormStateInterface $form_state) {
$form['edit'] = array(
'#type' => 'textfield',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Go'),
//'#markup' => "<div><a href='?word=1'>Go</a></div>",
);
return $form;
}
Now I want is; when I submit form,$form_state->getValue('edit');
should get appended as a query parameter in form route.
Let's say my form route is:
mymodule.admin_page:
path: '/mypage'
defaults:
_form: '\Drupal\mymodule\Form\myform'
And when I hit submit button of form, the route should get changed to /mypage?word=$form_state->getValue('edit')
.
I tried below approach, but it is throwing error:
Created 1 more route with a parameter:
mymodule.word:
path: '/mypage/{word}'
defaults:
_controller: '\Drupal\mymodule\Controller\AdminController::myfunction'
And in my form submit function,
function submitForm(array &$form, FormStateInterface $form_state) {
$data = $form_state->getValue('edit');
$url = Url::fromRoute('mymodule.word',['word'=>$data]);
$form_state->setRedirectUrl($url);
}
But when I hit submit button, it is giving me error,
Uncaught PHP Exception Symfony\Component\Routing\Exception\MissingMandatoryParametersException: "Some mandatory parameters are missing"