0

I've made a custom form in a module in Drupal 8, but I'd like to add target="_blank" in the form tag. When I try to add it in $form['#attributes']['target'], the attribute is shown in the wrapper of the form and not in the form tag itself.

Does anyone have an idea where this could be done?

3
  • If you want to directly control which element in HTML the attribute ends up on, you may need to turn to Twig. But, I have a feeling your use case probably matches one of those given in AyeshK's answer to #62577 and highly recommend you implement something from there. Feb 18, 2020 at 16:52
  • 1
    Does this answer your question? custom form submit in a new browser tab
    – leymannx
    Feb 18, 2020 at 16:55
  • Thx @IsaiahNixon. adding '#attributes' => array('onclick' => 'this.form.target="_blank";return true;'),' to the submit button did the trick for me.
    – Tim V
    Feb 19, 2020 at 15:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.