Reputation: 121
Okay, so I have a form. I want to be able to enter information and when I hit the submit button, download the information in a formatted matter.
For example, here is a basic form
<html>
<body>
<form action="submit.php" method="post">
<table>
<tr>
<td>Week of:</td>
<td><input type="text" name="week"></td>
</tr>
<tr>
<td>Monday:</td>
<td><input type="text" name="mon"></td>
</tr>
<tr>
<td>Tuesday:</td>
<td><input type="text" name="tue"></td>
</tr>
<tr>
<td>Wednesday:</td>
<td><input type="text" name="wed"></td>
</tr>
<tr>
<td>Thursday:</td>
<td><input type="text" name="thur"></td>
</tr>
<tr>
<td>Friday:</td>
<td><input type="text" name="fri"></td>
</tr>
<input type="submit">
</form>
</table>
</body>
</html>
Here is the submission page.
<html>
<body>
Your schedule for the week of <?php echo $_POST["week"]; ?> !<br>
Monday <?php echo $_POST["mon"]; ?> <br>
Tuesday <?php echo $_POST["tue"]; ?> <br>
Wednesday <?php echo $_POST["wed"]; ?> <br>
Thursday <?php echo $_POST["thur"]; ?> <br>
Friday <?php echo $_POST["fri"]; ?> <br>
</body>
</html>
The submission page displays the information into a different format. How can I get the information downloaded into a text document looking like this?
Upvotes: 0
Views: 169
Reputation: 4792
Check out: http://php.net/manual/en/function.header.php
You need to format your data in your preferred format after which you are able to do something similar to this:
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
Upvotes: 1