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

  • Home
  • SEARCH
  • 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 3792416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:37:08+00:00 2026-05-19T12:37:08+00:00

I have a basic script which generates dropdowns for age verification. What I want

  • 0

I have a basic script which generates dropdowns for age verification. What I want to do with this is add options to each dropdown at the beginning. So for day the first option would be ‘Day’, month – “Month”, year – “Year” each with a value of 0. Here’s the code:

<?php
//define the year
$thisYear = date('Y');
$filtered = array_map("strip", $_POST);

function strip($val){
$val = strip_tags($val);
$val = htmlentities($val,ENT_QUOTES);
return $val;
}

function renderDropDown($name, $opts, $valueIsKey=true){
$out = array();
$out[] = '<select name="'.$name.'">';
foreach($opts as $key => $val){
    if($valueIsKey){
        $out[] = '<option value="'.$key.'">'.$val.'</option>';
    } else {
        $out[] = '<option value="'.$val.'">'.$val.'</option>';
    }
}
$out[] = '</select>';

return implode("\n", $out);
}

if($_POST['submit'] != 'submit' && !isset($_POST['submit'])){
//define text months
for($i=2; $i<=13; $i++){
    $calTime = mktime(0, 0, 0, $i, 0, $thisYear);
    $months[date('m', $calTime)] = date('M', $calTime);
}
$renderHTML = true;
} else {    
    //try to construct a valid date from post data
if(checkdate($filtered['months'], $filtered['days'], $filtered['years'])){
    //valid date..check if they are 18+
    $validAge = $thisYear - 18;
    if($filtered['years'] <= $validAge){
        //inside you go
        die('yes');
    } else {
        header('Location: http://www.google.com');
    }
} else {
    //invalid date.. try again mr hacker
}
}

if($renderHTML){
?>
<form name="ageVerifier" action="" method="post">
    Day: <?php print(renderDropDown('days', range(1,31), false)); ?>
    Month: <?php print(renderDropDown('months', $months)); ?>
    Year: <?php print(renderDropDown('years', range($thisYear, $thisYear-100), false)); ?>
    <input type="submit" name="submit" value="submit" />
</form>
<?php
}
?>

Any help on this would be appreciated.

Cheers,
Chris

  • 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-05-19T12:37:09+00:00Added an answer on May 19, 2026 at 12:37 pm

    I am not sure if this is what you need.

    function renderDropDown($name, $opts, $valueIsKey=true){
        $out = array();
        $out[] = '<select name="'.$name.'">';
    
        $out[] = '<option value="0">'.ucfirst($name).'</option>';
    
        foreach($opts as $key => $val){
            if($valueIsKey){
                $out[] = '<option value="'.$key.'">'.$val.'</option>';
            } else {
                $out[] = '<option value="'.$val.'">'.$val.'</option>';
            }
        }
        $out[] = '</select>';
    
        return implode("\n", $out);
    }
    

    This is simple, but you’ll have the plural s at the end of each name. You may want to add an argument $title to the function, so it will become:

    function renderDropDown($name, $opts, $title, $valueIsKey=true){
    
        [...]
    
        $out[] = '<option value="0">'.$title.'</option>';
    
        [...]
    
    }
    

    You can call that function with something like:

    renderDropDown('days', range(1,31), "Day", false);
    

    Edit: you may want to look at this.

    Hope that helps.
    —Alberto

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

Sidebar

Related Questions

I have a perl script which when run from the command line generates a
Currently, i have basic C++ and PHP skills. But, i want to switch to
I have a basic model in which i have specified some of the fields
I have a basic ActiveRecord model in which i have two fields that i
I have a basic ajax application, which will not work, instead the php code
I'm developing this app which as a very basic Ajax form and I'm currently
I have a basic form with controls that are databound to an object implementing
I have a basic understanding of mock and fake objects, but I'm not sure
I have a basic CRUD form that uses PageMethods to update the user details,
I have a basic cs-major understanding of multi-threading but have never had to do

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.