Friday, June 22, 2012

Export html form content to Word documents



Purpose:
In HTML form, when users type  the content and click  "Export as MS Word" button, the content will be exported   in Word documents.
Code in PHP:
<form name="proposal_form" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post"">
 <textarea name="doc_body" id="doc_body" rows="5" class="mce-editor" style="width:100%; height:700px;"></textarea>
  <input type="submit" name="submit_docs" value="Export as MS Word" class="input-button" />
</form>
<?php
  if(isset($_POST['submit_docs'])){
          header("Content-Type: application/vnd.msword");
          header("Expires: 0");
          header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("content-disposition: attachment;filename=sampleword.doc");
         echo "<html>";
          $doc_body = $_POST['doc_body'];
           echo "$doc_body";
          echo "</html>";
          exit;
          }
?>

No comments:

Post a Comment