Error message not considering array
<p>I want an error message to appear if the 'Name' field is left empty but instead it displays error messages for all the fields in the form. </p>

<pre><code>$key = array('Name');
    foreach ($_POST as $key =&gt; $val) {
        while (is_array($val))
            $val = reset($val);
        if (is_string($val))
            $val = trim($val);
        if (empty($val)) {
            $err[] = "ERROR - $key is required";
        }
    }
</code></pre>
