I have a form embedded in a block in a node; when submitting the form, it has to do two things:
- Open another new window to a custom route
- Reload the current page
The first point works correctly, but refreshing the current page is not working. Here is a snippet of the code:
public function buildForm(array $form, FormStateInterface $form_state) {
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Join'),
];
$form['#attributes'] = ['target' => '_blank']; // Open new window.
}
public function submitForm(array &$form, FormStateInterface $form_state) {
// Open new window.
$form_state->setResponse(new TrustedRedirectResponse($url));
// Reload the current page.
$request = $this->getRequest();
$this->redirect($request->getUri());
}
I tried to use onclick="return location.reload();"
within the button tag but it fires before submitting the form.
Any ideas?
onclick="setTimeout(function(){location.reload();},1000)"