How to creat the button for 'Export'? Thanks!
I want to combine below two sets of code
<?php
echo"<a href='export.php?'>Export</a>
?> <?php
echo"<input type='button' value='Export'>";
?> How to creat the button for 'Export'? Thanks!
I want to combine below two sets of code
<?php
echo"<a href='export.php?'>Export</a>
?> <?php
echo"<input type='button' value='Export'>";
?> Brief summary: use semantic HTML and make the server actually send a file. As noted, either submit a form (works without JavaScript and lets you send filters/fields) or navigate to the export URL. ’s idea of styling a link is fine. Avoid nesting interactive elements (for example putting a link inside a button) — that causes unpredictable behavior in browsers.
Form-based, no-JS approach (recommended when you need to send data):
<form method="get" action="export.php">
<button type="submit">Export</button>
</form> Use GET for idempotent requests or POST if you’re submitting large payloads or sensitive data. Check the generated HTML in the browser (View Source) to confirm the form/action is correct.
Server-side: ensure export.php returns proper headers so the browser downloads the file. Minimal CSV example:
<?php
// export.php
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="export.csv"');
// output rows...
exit;
?> See the PHP header() docs and the HTTP Content-Disposition guidance for more details (php.net header, MDN Content-Disposition).
Troubleshooting (addresses , , and OP ):
<button> (can break clicks) — see the spec for details. Jump to Post— C#Jaap 5You'll have 2 options: (1) create a form so the button can submit to it's action or (2) you use the javascript onclick-event of the button to open export.php.
Jump to Post— almostbob 866or css style the <a>nchor to look like a button
You'll have 2 options: (1) create a form so the button can submit to it's action or (2) you use the javascript onclick-event of the button to open export.php.
or css style the <a>nchor to look like a button
Or you can do something like this
<button><a href='export.php?'>Export</a></button> After pressing the button, no respond!
Hi cliffcc
you need to add an 'onclick' event to make it work.
Try . . .
<button type="button" onclick="location='export.php'">Export</button> Zagga
Or you can do something like this
<button><a href='export.php?'>Export</a></button>
I've used this method, but unless you include a type in your button tag it acts as a submit button. I recommend this small modification:
<button type='button'><a href='export.php'>Export</a></button> edit: oops, didn't see Zagga's post. I've used the onclick solution and the href solution, both work.
Thanks all!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.