title: How can I output notification about missing form fields previously collected in an array?
body: <p>I have checked the <code>$_POST</code> data for missing required fields and generated an array of messages. Now I want to output those in one place, into the <code>&lt;div class"panel"&gt;</code> where the placeholder "Errors will go here" currently is. However, I have no idea how I can get it work.</p>
  
  <p>How can I output all the messages in this single place?</p>
  
  <p>My PHP code
      
  
  <pre><code>session_start();
  
  require_once 'libs/PHPMailer/PHPMailerAutoload.php';
  
  $errors = [];
  
  if(isset($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['message'])) {
  $fields = [
  'name' =&gt; $_POST['name'],
  'email' =&gt; $_POST['email'],
  'subject' =&gt; $_POST['subject'],
  'message' =&gt; $_POST['message']
  ];
  
  foreach($fields as $field =&gt; $data) {
      if(empty($data)) {
          $errors[] = 'The ' . $field . ' field is required.';
      }
  }
  } else {
  $errors[] = 'Something went wrong.';
  }
  
  $_SESSION['errors'] = $errors;
  header('Location: contact.php');
  ?&gt;
  </code></pre>
  
  <p>The HTML</p>
  
  <pre><code>&lt;section id="main" class="container 75%"&gt;
                  &lt;header&gt;
                      &lt;h2&gt;Contact Us&lt;/h2&gt;
                      &lt;p&gt;Submit all questions and concerns here and we will respond as soon as possable!&lt;/p&gt;
                  &lt;/header&gt;
                  &lt;div class="box"&gt;
                  &lt;div class="panel"&gt;
                  Errors will go here
                  &lt;/div&gt;
                      &lt;form method="post" action="contactformmail.php"&gt;
                          &lt;div class="row uniform 50%"&gt;
                              &lt;div class="6u 12u(mobilep)"&gt;
                                  &lt;input type="text" name="name" id="name" value="" placeholder="Name" /&gt;
                              &lt;/div&gt;
                              &lt;div class="6u 12u(mobilep)"&gt;
                                  &lt;input type="email" name="email" id="email" value="" placeholder="Email" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="row uniform 50%"&gt;
                              &lt;div class="12u"&gt;
                                  &lt;input type="text" name="subject" id="subject" value="" placeholder="Subject" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="row uniform 50%"&gt;
                              &lt;div class="12u"&gt;
                                  &lt;textarea name="message" id="message" placeholder="Enter your message" rows="6"&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="row uniform"&gt;
                              &lt;div class="12u"&gt;
                                  &lt;ul class="actions align-center"&gt;
                                      &lt;li&gt;&lt;input type="submit" value="Send Message" /&gt;&lt;/li&gt;
                                  &lt;/ul&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/section&gt;
  </code></pre>