-1

Currently I am using a hidden form (for reasons decided upon by others, not myself) to act as a link so it can post data with itself. This "link" always opens in the same window, and the general tricks I have tried don't let it open in a new tab instead. This is the current code, any tips?

<tr><td>
  <form method="post" action="myPage.php" class="inline">
  <input type="hidden"  name="submit_parassmHidden" value="extra_submit_value">
    
  <button type="submit"  name=".$dataIAmPassingToNextPage." value="submit_value" class="link-button">"
.$linkTitle."</button></form>
</td>";

^Took out the escape slashes to be easier to read, its in PHP, its echo so it shows as regular HTML.

Things like target="_blank" dont seem to be working for me or I am putting them in the wrong place. Anyone have ideas on how I could do this?

EDIT: Since people are saying I can't be doing both, this is what I am doing. It LOOKS like a normal link, there is no form, it IS HIDDEN.

"Ok you're saying 2 different things here. The form is either hidden or you can see the submit link. Both can't be true" <- From comments. Clearly it is true, the form is hidden, and you can see the submit link. However I want these "Links" (which are really buttons in disguise) to open in the new tab.

enter image description here

Community
  • 1
  • 1
Lain
  • 2,166
  • 4
  • 23
  • 47
  • Is the whole form hidden or is it just a form with a hidden field and a button? – apokryfos Feb 16 '18 at 14:18
  • `target="_blank"` is an attribute of the `
    ` tag but you could also use `formtarget="_blank"` on the button: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
    – CD001 Feb 16 '18 at 14:24
  • @apokryfos whole form is hidden, it looks just like a regular link when done like this. Also not sure why this got downvoted. The provided solutions are for type links, which is clearly not what I have and do not work, hence my problem. – Lain Feb 16 '18 at 15:29
  • Ok you're saying 2 different things here. The form is either hidden or you can see the submit link. Both can't be true – apokryfos Feb 16 '18 at 15:56
  • @apokryfos I have edited my post with a picture, since you seem to think it can't be done. This is what it does, it shows the submit link AND hides the form part, the link just sends data. I want it to do it in new window. – Lain Feb 16 '18 at 16:21
  • The form is a collection of elements. Hiding the form implies hiding that collection of elements. In your case your form is not hidden at all. – apokryfos Feb 16 '18 at 16:53

1 Answers1

0

Unfortunately you have not another option.

target="_blank" or button with formtarget="_blank" in HTML5 (like @CD001 comment) is the solution.

_blank Opens the linked document in a new window or tab depending on the user's browser configuration.

But I saw a little trick here: https://stackoverflow.com/a/15551850/2951051 someone who say to use target="_tab" even if not exist (I dont know if it really work)

<tr><td>
  <form method="post" action="http://stackoverflow.com" class="inline" target="_blank">
  <input type="hidden"  name="input_name" value="extra_submit_value">

  <button type="submit"  name="form_name" value="submit_value" class="link-button">test</button></form>
</td>
MTK
  • 3,300
  • 2
  • 33
  • 49
  • Neither of those work, have tried both. Its not a regular link, if you notice those are for a href tags which I do NOT have and therefore it does not work. – Lain Feb 16 '18 at 15:27
  • So is some from your browser configuration. I have tried now your code in local and working good. stackoverflow is oppened in a new tab (see the code above in mi answer). I have tried it in chrome 64, Edge 20. Firefox 32, and Opera 34. (All work) – MTK Feb 16 '18 at 15:59
  • One question: In your code you have `name=\submit_parassmHidden"` why you have a slash an not double quotes? is a typo? – MTK Feb 16 '18 at 16:09
  • Was removing the / from php, messed up while transfering it over. Was trying to make it easier to read for asking. – Lain Feb 16 '18 at 16:23