title: html form with required fields
body: <p>I have a form that is currently working but want to add php code to the "post" file so some fields in the html form are required otherwise a message displays.</p>
  
  <p>heres my html code at the moment.</p>
  
  <pre><code>&lt;form action="contact.php" method="post"&gt;
        &lt;input type="text" class="main" name="cf_name" value="Name (Required)" size="31" /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;input type="text" class="main" name="cf_company" value="Company" size="31" /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;input type="text" class="main" name="cf_phone" value="Phone (Required)" size="31" /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;input type="text" class="main" name="cf_email" value="Email (Required)" size="31" /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
      &lt;textarea type="text" name="cf_text0" cols="34" rows="3" class="main"&gt;Message&lt;/textarea&gt;
        &lt;br /&gt;
        &lt;input type="image" src="images/send.jpg" height="16" width="41" border="0"
        alt="Submit Form" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and heres my php code</p>
  
  <pre><code>&lt;?php
  $field_name = $_POST['cf_name'];
  $field_company = $_POST['cf_company'];
  $field_phone = $_POST['cf_phone'];
  $field_email = $_POST['cf_email'];
  $field_message = array($_POST["cf_text0"],);
  
  $mail_to = 'callum@colmandesigns.co.nz';
  $subject = 'A &amp; J Print - Contact Form '.$field_name;
  
  $field_message="From: {$field_name}
  Company: {$field_company}
  Phone: {$field_phone}
  Email: {$field_email}
  Message: {$field_message[0]}";
  
  
  $headers = 'From: '.$field_email."\r\n";
  $headers .= 'Reply-To: '.$field_email."\r\n";
  
  $mail_status = mail($mail_to, $subject, $field_message, $headers);
  
  if ($mail_status) { ?&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          alert('Thank you for the message. We will contact you shortly.');
          window.location = 'index.html';
      &lt;/script&gt;
  &lt;?php
  }
  else { ?&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          alert('Message failed. Please, send an email to craig@colmandesigns.co.nz');
          window.location = 'index.html';
      &lt;/script&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>I want to have the Name, Phone and Email fields required. </p>
  
  <p>Thanks,
  Callum</p>