• New Commercial Services Section

    We have now opened a commercial services section here on the forum. If you have a Fabrik project that you wish to have someone work on for you, post it under Help Wanted. If you are an application developer and wish to earn some money helping others, post your details under Fabrik Application Developers.

    Both of these are unmoderated. It will be up to both parties to work out the details and come to an agreement.

PHP Validation of form element

I'm struggling with this validation and hoping someone can help me improve my php. The form is a booking form and the field is a date element. The rule is, a booking date can be for the next day if made prior to 9am today, otherwise the minimum date is the day after tomorrow. There is obviously an issue in my code though as every date entered is accepted. My code is as follows:
PHP:
$app = JFactory::getApplication();
$data = JFactory::getDate($data)->toUnix();
//date entered
$day=date('D',strtotime($data));
//today
$date = new DateTime($string);

if (date('H',strtotime($date)) < 9) {
   $minDate = date('D',strtotime($date).' + 1 day' );
  }
else {$minDate = date('D',  strtotime($date).' + 2 days' );
}
if( $minDate <= $day){return true;}
else{return false;}
 
This should do:
Code:
$booking_date = date("Y-m-d", strtotime($data));
$hour_now = date("G");

if($hour_now < 9) {
  $min_date = date("Y-m-d", strtotime("+ 1 day"));
} else {
  $min_date = date("Y-m-d", strtotime("+ 2 day"));
}

return $booking_date >= $min_date;

You can always do a var_dump($variable_name);exit; in your code to see the actual values. E.g. date('D',strtotime($data)); gives you "Thu" and not numeric value. And then below you compare it to another day like if Thu > Fri, so you obviously get unexpected results.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top