Jump to content

Help with a date select box


mikeoffy69

Recommended Posts

So I have this program I purchased and it allows me to create custom form fields. I have been trying to create a date select box but have been struggling because I am just learning php. I was wondering if someone could lend a hand.  I will try and give as much info as i can.  First I will show a picture of the custom field box and then i will give the description of both boxes that the company gave me. Next i will give you the php code i have been trying to work with. Please if my code is not the best then i will take any advice. I found the code for the date selector online.

 

formro.jpg

 

Parsed Default Value  -  You may specify a variable or a function as the default value; for example $_SERVER[HTTP_USER_AGENT] or mktime()

 

 

Parsed PHP Code -    You can specify actual PHP code that will be used to return a variable. // You should assign the value you wish to use to the variable $str.

 

 

<?PHP

FUNCTION buildDate($name, $m, $d, $y) {
        $date = DATE("m-d-Y",STRTOTIME("now"));
        $date_array = EXPLODE("-",$date);
        $now_m = "";
        $now_d = "";
        $now_y = "";
        $month = '<select class="small" name="'.$name.'_month">';
        $month .= '<option value="" selected disabled>mm</option>';
        FOR ($i=1;$i<=12;$i++) {
                IF ( $m != "" ) {
                        IF ( $m == $i ) {
                                $now_m = "selected";
                        }
                }ELSEIF ( $m == "0" ) {
                        $now_m = "";
                }ELSE{
                        IF ( $date_array[0] == $i ) {
                                $now_m = "selected";
                        }
                }
                $month .= '<option value="'.$i.'" '.$now_m.'>'.$i.'</option>';
                $now_m = "";
        }//END month for loop
        $month .= '</select>';
        $day = '<select class="small" name="'.$name.'_day">';
        $day .= '<option value="" selected disabled>dd</option>';
        FOR ($i=1;$i<=31;$i++) {
                IF ( $d != "" ) {
                        IF ( $d == $i ) {
                                $now_d = "selected";
                        }
                }ELSEIF ( $d == "0" ) {
                        $now_d = "";
                }ELSEIF ( $d == $i ) {
                        $now_d = "selected";
                }ELSE{
                        IF ( $date_array[1] == $i ) {
                                $now_d = "selected";
                        }
                }
                $day .= '<option value="'.$i.'" '.$now_d.'>'.$i.'</option>';
                $now_d = "";
        }//END day for loop
        $day .= '</select>';
        $year = '<select class="small" name="'.$name.'_year">';
        $year .= '<option value="" selected disabled>yyyy</option>';
        FOR ($i=GMDATE("Y"); $i <=SUBSTR(get330Date(),0,4); $i++) {
                IF ( $y != "" ) {
                        IF ( $y == $i ) {
                                $now_y = "selected";
                        }
                }ELSEIF ( $y == "0" ) {
                        $now_y = "";
                }ELSEIF ( $y == $i ) {
                        $now_y = "selected";
                }ELSE{
                        IF ( $date_array[2] == $i ) {
                                $now_y = "selected";
                        }
                }
                $year .= '<option value="'.$i.'" '.$now_y.'>'.$i.'</option>';
                $now_y = "";
        }//END year for loop
        $year .= '</select>';
        //-------------------------------------------
        ECHO $month." ".$day." ".$year;
}//END buildDate function
// ------------------------------------
FUNCTION get330Date() {
        RETURN DATE("Y-m-d", MKTIME(0, 0, 0, SUBSTR(GMDATE("Y m d"),5,2), 
        SUBSTR(GMDATE("Y m d"),8,2) + 330, 
        SUBSTR(GMDATE("Y m d"),0,4)))."<br />";
}

?>

 

 

 

I might just be totaly wacked here with what i am trying to do but i am sure someone will tell me one way or the other. lol

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.