title: PHP or HTML Form Validation
body: <p>I want to validate an HTML form in either HTML or PHP. By validate, I mean ensuring there is at least 1 character of text entered into each of the 2 textboxes. And either only alpha numeric characters entered, or have something that ensures that any punctuation doesn't end up with "/" before it.</p>
  
  <p>At the moment my form is made up of 2 php pages (copied below), and then posted to a txt file. </p>
  
  <p>I'm either after some (very basic) instructions on how to do it, or suggestions on my script below.</p>
  
  <pre><code>//HTML
  &lt;form style="" method="post" action="addtopic2.php"&gt;
  Topic:&lt;input name="topic" id="topicbox" maxlength="100" type="text"&gt;&lt;br&gt;
  Outline: &lt;textarea input wrap="nowrap" rows="10" cols="120" 
  name="outline"&gt;&lt;/textarea&gt;    
  &lt;br&gt;&lt;input name="submit" value="Submit" type="submit"&gt;
  &lt;/form&gt;
  //HTML
  
  &lt;?php
  $t = "Topic:";
  $o = "Outline:";
  
  $topic = $_POST['topic'];
  $outline = $_POST['outline'];
  
  $data = "$t $topic | $o $outline |\n";
  
  $fh = fopen("users.txt", "a");
  fwrite($fh, $data); 
  fclose($fh); 
  ?&gt;
  </code></pre>
  
  <p>//ATTEMPTED TO USE FOLLOWING,  BUT DOESNT SEEM TO WORK WHEN INSERTING INTO EITHER PAGES.</p>
  
  <pre><code>&lt;?php
  if($_POST['Submit'] == "submit")
  {
    $errorMessage = "";
    if(empty($_POST['topic']))
    {
  $errorMessage .= "&lt;li&gt;A topic needs to be entered&lt;/li&gt;";
    }
    if(empty($_POST['outline']))
    {
      $errorMessage .= "&lt;li&gt;An outline needs to be entered&lt;/li&gt;";
    }
    $vartopic = $_POST['formtopic'];
    $varoutline = $_POST['formoutline'];
    if(!empty($errorMessage))
    {
      echo("&lt;p&gt;There was an error with your form:&lt;/p&gt;\n");
          echo("&lt;ul&gt;" . $errorMessage . "&lt;/ul&gt;\n");
    }
  }
  ?&gt;
  
  
  &lt;?php
  if (isset($_POST['topic']) &amp;&amp; isset($_POST['outline'])) {
       $topic = trim($_POST['topic']);
      $outline = trim($_POST['outline']);
  }
  else {
    echo '&lt;p&gt;Fill the form&lt;/p&gt;';
  }
  ?&gt;
  </code></pre>