Ching Ling
Ching Ling

Reputation: 301

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?

Upvotes: 4

Views: 19072

Answers (1)

hakre
hakre

Reputation: 197732

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

<form id="myform"></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):

Upvotes: 7

Related Questions