Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make the first option in a drop down list an unacceptable answer?
    primarykey
    data
    text
    <p>Okay so I have a form and within this form are a bunch of required fields. The birthday part of this form consists of 3 fields: month, day, and year. Now what I want to do is have the words "Month:", "Day:", and "Year:" at the top of the drop down lists, BUT I do not want these options to be acceptable answers! When I submit the form without selecting an actual month, day, and year, it should say that the month, day, and year are required when I print the errors! How can I accomplish that? My "if statements" that make the fields required are at the bottom of this code:</p> <pre><code>&lt;form action="" method="post"&gt; &lt;ul id="register"&gt; &lt;li&gt; Birthday: &lt;select name="month"&gt; &lt;option value="month"&gt;Month:&lt;/option&gt; &lt;option value="January"&gt;January&lt;/option&gt; //all the other months &lt;/select&gt; &lt;select name="day"&gt; &lt;option value="day"&gt;Day:&lt;/option&gt; &lt;option value="1"&gt;1&lt;/option&gt; //all the other days of the month &lt;/select&gt; &lt;select name="year"&gt; &lt;option value="year"&gt;Year:&lt;/option&gt; &lt;option value="2013"&gt;2013&lt;/option&gt; //more year options &lt;/select&gt;&lt;br&gt;&lt;br&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="submit" name="registrationform" value="Sign up"&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/form&gt; &lt;?php if (!empty($_POST['registrationform'])) { if(isset($_POST['registrationform'])){ $required_fields = array('month', 'day', 'year'); foreach ( $required_fields as $key=&gt;$value) { if (!isset($_POST[$value]) || $_POST[$value]=='') { $errors[$value] = $key." is required"; } } print_r($errors); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload