Jump to content

help me to validate calendar function


raj86

Recommended Posts

HI FRIENDS

i am new in php......i am having 3 date field in my so for that i am using below calendar code but i am having 3 querys on it.....please help me

1) how to use this function in html form???

2)  how to validate it, i.e avoid from unavailable date, leap year etc.......

3) i need to send its value in data base and when i press submit the vlaue should not reset

//This function makes 3 pulldown menus for the months, days, and years.
         function make_calendar_pulldowns2($m2 = NULL, $d2 = NULL, $y2 = NULL)
         {
	 //Make the years pull-down menu.
            echo '<select name="year2">';
            for ($year2 = 1960; $year2 <= 2022;
            $year2++)
               {
               echo "<option value=\"$year2\"";
               if ($year2 == $y2)
                  {
                  //Preselect.
                  echo ' selected="selected"';
                  }
               echo ">$year2</option>\n";
               }
            echo '</select>';

         //Make the months array.
         $months2 = array (1 => '1','2','3','4','5','6','7','8','9','10','11','12');
            
            //Make the months into a pulldowm.
            echo '<select name="month2">';
            foreach ($months2 as $key => $value)
               {
               echo "<option value=\"$key\"";
               if ($key == $m2);
                  {
                  //Preselect.
                  echo ' selected="selected"';
                  }
               echo ">$value</option>\n";   
               }
            echo '</select>';
            
            //Make the days pull-down menu.
            echo '<select name="day2">';
            for ($day2 = 1; $day2 <= 31; $day2++)
               {
               echo "<option value=\"$day2\"";
               if ($day2 == $d2)
                  {
                  //Preselect.
                  echo ' selected="selected"';
                  }
               echo ">$day2</option>\n";
               }
            echo '</select>';
         }//End of Function Definition
         
     
         //Get today's date and call the function.

         $dates2 = getdate();
         $date_birth = "make_calendar_pulldowns2";
	 $date_join = "make_calendar_pulldowns2";
	 $date_term = "make_calendar_pulldowns2"; 

Link to comment
https://forums.phpfreaks.com/topic/176159-help-me-to-validate-calendar-function/
Share on other sites

So I take it you didn't write the code.

 

1) how to use this function in html form???

 

<form action="" method="post">
<?php make_calendar_pulldowns2() ?> 
</form>

 

2)  how to validate it, i.e avoid from unavailable date, leap year etc.......

 

<?php
if(checkdate($_POST['year2'] . "-" . $_POST['month2'] . "-" . $_POST['day2'])) {
  echo "Valid";
}
?>

 

3) i need to send its value in data base and when i press submit the vlaue should not reset

 

Change part 1 to the following will stop the values reseting on submit.

 

<form action="" method="post">
<?php make_calendar_pulldowns2($_POST['month2'], $_POST['day2'], $_POST['year2']) ?> 
</form>

 

As far as adding to the database, depends what database your using, the structure, etc, etc, etc.

HELLO cags/friends

  i am using wampserver 2.0i...and am using the  phpmyadmin (sql datbase) and my field type is date only....please help me , how can i insert the date in database

 

 

and am using 3 date fields......for these 3 differnt fields i am having differnt validations these are.......

1) date of birth

2) date of joining

3) termination date

 

so can u tell me any method so that i can store this function in 3 different variables and can proceed the validation

 

your reply for 2) question i am not getting because i am using year2, month2 and day2 inside the function ....please tell me this code i have to use inside the function or outside the function....i am new to this please help me

<?php
if(checkdate($_POST['year2'] . "-" . $_POST['month2'] . "-" . $_POST['day2'])) {
  echo "Valid";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.