Submit Button without a form

So what I want is a button, that when clicked, sends an article id to a php page through GET request, and the PHP page generates a PDF summary of my article.

Now this is fairly simple to do if I had a form tag, but I don't and I can't have one since my button is in a table, and as far as I know, forms cannot exist in tables. I still tried using a form tag but it was breaking my site so that's not an option.

The following is what I have:

echo "<td><button type=\"submit\" formaction=\"wp-content/themes/csed/data-entry/results.php\" formmethod=\"get\"class=\"button\" name=\"id\" value=\"" .$single->idArticle. "\" formtarget=\"_blank\">PDF</button></td>";

As you can see, I tried using the formaction attribute to make this work, but right now, my button does not do anything. Anything at all. What am I doing wrong? Is what I'm trying to achieve even possible?

5

1 Answer

If you can not place the button into the form element, you can associate it to one via the form's ID:

<form></form>
...
<button form="myform" ... >

So the <form> element can be anywhere else in the hypertext document, be it before or even after the button. The button must not be a descendant of the form.

I quickly compiled this rudimentary example from the MDN docs which are available in different languages even (although I as non native English speaker normally prefer the English variant):

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like