hi, am recieving an undefined offset error for $month and $year line after the explode function. This happens only when the form is blank and submitted.

 $dob="dd/mm/yyyy";
 $dob= $_POST['dob'];   

function icPrintINPUTbirth($label,$name,$maxlth,$size,$value)
                {
                print '<label>'.$label.':<input type="text" name="'.$name.'" 
                maxlength="'.$maxlth.'" size="'.$size.'" value="'.$value.'"/></label>'.'';
                }

 icPrintINPUTbirth("Date of Birth (dd/mm/yyyy) ","dob",10,10,$dob); 


        $arr=explode("/","$dob"); 
                    $day=$arr[0];
                    $month=$arr[1];
                    $year=$arr[2];

     if(@checkdate($month, $day, $year)){
                    print ''; 
                }else{
                    $errs[]= "The date entered is not valid, please try again </br>";
                    }

CHeers

Member Avatar for diafol

why are you running a function without validating the data first? You can try something like this.
Here's a resource: http://stackoverflow.com/questions/2086598/validate-date-format-in-php?answertab=votes#tab-top

function validDate($date) {
    if (substr_count($date, '/') == 2) {
        list($day, $month, $year) = explode('/', $date);
        return checkdate($month, $day, sprintf('%04u', $year));
    }
    return false;
}

$date = false;
if(!empty($_POST['date']))$date = validDate($_POST['date']);

if($date){
    $d = $_POST['date'];
    echo "<label>Date of Birth (dd/mm/yyyy) :<input type=\"text\" name=\"dob\" maxlength=\"10\" size=\"10\" value="\$d\" /></label>";
}else{
    $errs[]= "The date entered is not valid, please try again </br>";
}

I just took the function apart as it looked like it was a one shot - not designed to be re-used.

Change this

 $dob= $_POST['dob'];  

to

if(isset($_POST['dob']))  $dob = $_POST['dob'];
 $dob = 'xx/xx/xxxx';

@Bachov: That does solve the issue. If $_POST['dob'] contains 02/03 he will still get the error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.