Score:-2

How to add an external link inside form actions?

ca flag

I want to programmatically add an external link next to my submit button in a form that I have created.

ca flag
If you consider that my question has not been correctly formulated is fine and therefore I understand the downvotes, but if you do want help next time, add a comment at least explaining why my question is wrong...
cn flag
People are explicitly discouraged from commenting on downvotes - I'm sure this won't be the case for you personally, but it too often leads to name-calling and revenge voting, which messes up the site. If you hover over the downvote arrow you'll see a tooltip explaining the general reason, which I think it's fair to say does apply here
ca flag
@Clive I didn't know about that feature and that it was discouraged, so thanks for you comment!
Score:1
ca flag

The solution that worked for me was adding a link element within the actions array

$form['actions']['google_search'] = [
      '#type' => 'link',
      '#title' => $this->t('Google Search'),
      '#url' => Url::fromUri('https://www.google.com/search?whatever'),
      '#attributes' => ['target' => '_blank', 'class'=> 'button'],
    ];

Ps: Directly adding the url to the #url element does not work, I had to use the Url component

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.