Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:16:56+00:00 2026-06-16T22:16:56+00:00

Okay so I have a form and within this form are a bunch of

  • 0

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:

<form action="" method="post">  
        <ul id="register">
            <li>
                Birthday:

                <select name="month">
                    <option value="month">Month:</option>
                    <option value="January">January</option>
                    //all the other months
                </select>

                <select name="day">
                    <option value="day">Day:</option>
                    <option value="1">1</option>
                    //all the other days of the month
                </select>

                <select name="year">
                    <option value="year">Year:</option>
                    <option value="2013">2013</option>
                    //more year options
                </select><br><br>
            </li>

            <li>
                <input type="submit" name="registrationform" value="Sign up">
            </li>
        </ul>
    </form>
    <?php
    if (!empty($_POST['registrationform'])) {
    if(isset($_POST['registrationform'])){
        $required_fields = array('month', 'day', 'year');
        foreach ( $required_fields as $key=>$value) {
         if (!isset($_POST[$value]) || $_POST[$value]=='') {
              $errors[$value] = $key." is required";

            }
   }

   print_r($errors);
}
    }

    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:16:58+00:00Added an answer on June 16, 2026 at 10:16 pm

    Use optgroup

    <select name="month">
      <optgroup label="Month:">
        <option value="January">January</option>
        //all the other months
      </optgroup>
    </select>
    
    etc.
    

    JSFiddle

    or disable the option and select the title if you want the title to show – once the list is touched, the title will not be selectable.

    <select name="month">
        <option disabled="disabled" selected="selected">Month:</option>
        <option value="January">January</option>
        //all the other months
    </select>
    

    JSFiddle

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, right now I have a form that contains this select list: <%=Html.LabelFor(x =>
Okay so say I have a form element like this: HTML: <div class=form-item> <label>Current
Okay, so I have this form that is set to preload a DB record
Okay this is what I have so far. I have a form that needs
Okay, I have this form and I want to submit a page in the
I have an HTML form with a bunch of input fields (of type text
Okay so I have this website where I have a form on the sidebar
Okay, I have this textfield form that contains some text. What I need to
Okay all, I have a form that I want users to fill out. When
Okay, next PHPExcel question. I have an HTML form that users fill out and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.