Page 1 of 1

Logic problem

Posted: Sun Feb 24, 2008 8:34 am
by PhpDog
I have created a function, validDate(), which validates dates. It returns 0 if the format is OK and the date is valid.
I need to check two textfields for possible user date input. Such input is only meaningful if they have first selected a date field, from a select list, to search from which is called $dates.

So I have:

Code: Select all

 
if((validDate($dateFrom) == 0) || (validDate($dateTo) == 0) && ($dates == "Please select a date field to search on"))
{
    $errors = 1;
 $table .= 
     "
      <table width='100%'  border='0' cellpadding='1'>
                  <tr>
                        <td class='warning'><div align='center'>ERROR! - Please select a date field to search on</div></td>
                  </tr>
               </table> 
     ";
     
}
 
but it is not operating as expected right now. Can anyone please see where my logic is at fault?

If either of the date validations returns zero and $dates == "Please select a date field to search on" then generate the html error message.

Re: Logic problem

Posted: Sun Feb 24, 2008 12:00 pm
by Christopher
You probably want:

Code: Select all

if( ( (validDate($dateFrom) == 0) || (validDate($dateTo) == 0) ) && ($dates == "Please select a date field to search on"))
Also, wouldn't it make more sense for validDate() to return true if valid and false if not? Or rename it invalidDate().

Re: Logic problem

Posted: Sun Feb 24, 2008 3:47 pm
by PhpDog
arborint wrote:You probably want:

Code: Select all

if( ( (validDate($dateFrom) == 0) || (validDate($dateTo) == 0) ) && ($dates == "Please select a date field to search on"))
Also, wouldn't it make more sense for validDate() to return true if valid and false if not? Or rename it invalidDate().
In the cold light of today - yes! When I orignally wrote it, somehow if made perfect sense. :lol: Oh ,dear ....