title: don't send the form message if input is empty
body: <p>i do have a little problem with my contact.php :(</p>
  
  <p>I needed for my page a contact form (very simple, just name, email and message).
  It works perfectly but it sends the message even if the inputs are empty. My inputs do have "required" but it doesn't seem to work. My php skills are not that great. But you understand for sure where the problem is. </p>
  
  <p>If there are empty fields, the form should not send the message and show an alert.</p>
  
  <p>My current code:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>    &lt;form method="post" id="myform" action="contact.php"&gt;
          &lt;div class="field half first"&gt;
              &lt;label for="name"&gt;Ihr Name&lt;/label&gt;
              &lt;input type="text" name="name" id="name" required="required"&gt;
          &lt;/div&gt;
          &lt;div class="field half"&gt;
              &lt;label for="email"&gt;Ihre E-Mail&lt;/label&gt;
              &lt;input type="text" name="email" id="email" required="required"&gt;
          &lt;/div&gt;
          &lt;div class="field"&gt;
              &lt;label for="message"&gt;Ihre Nachricht&lt;/label&gt;
              &lt;textarea name="message" id="message" rows="5" required="required"&gt;&lt;/textarea&gt;
          &lt;/div&gt;
          &lt;ul class="actions"&gt;
              &lt;li&gt;
                  &lt;a href="" class="button submit"&gt;Senden&lt;/a&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p><strong>contact.php</strong></p>
  
  <pre><code>&lt;?php 
  $field_name = $_POST['name'];
  $field_email = $_POST['email'];
  $field_message = $_POST['message'];
  
  $mail_to = 'mail@gmail.com';
  $subject = 'Nachricht von '.$field_name;
  
  $body_message = 'Von: '.$field_name."\n";
  $body_message .= 'E-mail: '.$field_email."\n";
  $body_message .= 'Nachricht: '.$field_message;
  
  $headers = 'Von: '.$field_email."\r\n";
  $headers .= 'Antworte an: '.$field_email."\r\n";
  
  $mail_status = mail($mail_to, $subject, $body_message, $headers);
  
  if ($mail_status) { ?&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          alert('Ich bedanke mich für Ihre Nachricht. Bald werde ich Sie kontaktieren./ Thank you for your message.');
      window.location = 'http://';
      &lt;/script&gt;
      &lt;?php
       }
  else { ?&gt;
       &lt;script language="javascript" type="text/javascript"&gt;
          alert('Senden fehlgeschlagen./ Could not send the message');
      window.location = 'http://';
       &lt;/script&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>Any ideas, how to fix that small problem? :(</p>