title: html php form store results in a text file
body: <p>I am using following html, php code. Everything works fine. I can store the html form submitted values to a text file. But when I load the html page I see following when doing tail -f filename. </p>
  
  <pre><code>mytext.txt: file truncated
  </code></pre>
  
  <p>I looks like when the page loads or is refreshed text file is written with no values. How can I only write the values when submit button is clicked and not write when page loads. </p>
  
  <pre><code>&lt;?php
  $action = $_GET["action"];
  $customer = $_POST["customer"];
  $ourref = $_POST["ourref"];
  $custref = $_POST["custref"];
  $comments = $_POST["comments"];
  $wipe = $_POST["wipe"];
  
  
  $data = array($customer, $ourref, $custref, $comments, $wipe);
  if($action = "save") {
    file_put_contents("mytext.txt", implode(':',$data));
        }
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="main.css"&gt;
   &lt;title&gt;Customer Information&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="wipemain"&gt;
  &lt;h2&gt; Test &lt;/h2&gt;
  &lt;h3&gt; This information will be used by the data wiping system &lt;/h3&gt;
    &lt;form action="?action=save" name="myform" method="post"&gt;
      Enter Customer Name:
      &lt;input type=text size=80 name="customer"&gt;&lt;/br&gt;&lt;/br&gt;
      Enter Our Reference Name:
      &lt;input type=text size=76 name="ourref"&gt;&lt;/br&gt;&lt;/br&gt;
      Enter Customer Reference Number:
      &lt;input type=text size=69 name="custref"&gt;&lt;/br&gt;&lt;/br&gt;
      Comments:
      &lt;input type=text size=91 name="comments"&gt;&lt;/br&gt;&lt;/br&gt;
      Select the Data Wiping Method:
      &lt;select name="wipe"&gt;
      &lt;option value="zero"&gt;Default - Quick and Secure - Write Zeros across the spindles&lt;/option&gt;
      &lt;option value="dod522022m"&gt;dod522022m / dod       - 7 pass DOD 5220.22-M method&lt;/option&gt;
      &lt;option value="dodshort"&gt;dodshort / dod3pass    - 3 pass DOD method&lt;/option&gt;
      &lt;option value="gutmann"&gt;gutmann                - Peter Gutmann's Algorithm&lt;/option&gt;
      &lt;option value="ops2"&gt;ops2                   - RCMP TSSIT OPS-II&lt;/option&gt;
      &lt;option value="random"&gt;random / prng / stream - PRNG Stream&lt;/option&gt;
      &lt;option value="zero"&gt;zero / quick           - Overwrite with zeros&lt;/option&gt;
      &lt;option value="dod522022m"&gt;U.S. Navy Staff Office Publication NAVSO P-5239-26&lt;/option&gt;
      &lt;option value="gutmann"&gt;British HMG Infosec Standard 5, Enhanced Standard&lt;/option&gt;
      &lt;option value="ops2"&gt;New Zealand Government Communications Security Bureau NZSIT 402&lt;/option&gt;
      &lt;option value="random"&gt;Australian Government ICT Security Manual 2014 - Controls&lt;/option&gt;
  
  
      &lt;/select&gt;
      &lt;/br&gt;&lt;/br&gt;
      &lt;input type="submit" size=40 onclick="clicked" value="save"&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  &lt;script type="text/javascript"&gt;
  /** function clicked() {
         if (confirm('Do you wanna to submit? Click here to confirm and close this Window')) {
             yourformelement.submit();
         } else {
             return false;
         }
      } */
  function clicked() {
             alert("Successfully Processed - Now you can close this Window job"); }
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Your help  is appreciated.</p>