Reputation: 4069
HTML5 introduced a nice feature for marking <a>
links as download endpoints, by simply adding download
attribute to the <a>
tag (see description).
Is it possible to do the same for HTML forms?
Here is a simple use case for example: I have a form that requests the user for some details, and after the user submits the form the server should return a file according to these details.
Upvotes: 6
Views: 3184
Reputation: 156968
No, form
doesn't have a download
attribute, so it is not possible to have that exact behavior with a form
.
You can set the output file name through a post though, by setting the Content-Disposition
HTTP header:
Content-Disposition: attachment; filename="yourPicture.png"
Upvotes: 1
Reputation: 56
This is not possible. According to the specification is the "download" attribute only specified for a and area.
http://www.w3.org/html/wg/drafts/html/master/links.html#downloading-resources
Upvotes: 4
Reputation: 2147
Yes after submitting data you can return file in form of pdf or else. By using header function
<?php
//create pdf with details
.....
.
.
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
?>
But this is not possible using download attribute
Upvotes: -1