简体   繁体   中英

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?

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):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM