Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

sanitize_date_field_input()

Parameters

ColumnTypeDefaultDescription
$date
$validate false

Location

include/resource_functions.php lines 6974 to 7003

Definition

 
function sanitize_date_field_input($date$validate=false)
    {
    
$year   sprintf("%04d"getvalescaped("field_" $date "-y",""));
    
$month  getval("field_" $date "-m","");
    
$day    getval("field_" $date "-d","");
    
$hour   getval("field_" $date "-h","");
    
$minute getval("field_" $date "-i","");
    
    
// Construct value, replacing missing parts with placeholders
    
$val  = ($year != "" && $year != "0000") ? $year "year";
    
$val .= "-" . ($month != "" $month "month");
    
$val .= "-" . ($day != "" $day "day");
    
$val .= " " . ($hour != "" $hour "hh");
    
$val .= ":" . ($minute != "" $minute "mm");
    if(
$validate
        {
        
# Format dates for the date validator e.g. 2020, 2020-month-29 by stripping unused placeholders
        
$removedates = array("year-month-day","-month-day","-day"," hh:mm");
        
$val str_replace($removedates,"",$val);
        }
    else
        {
        
# Format for database entry e.g. 2020-00-00, 2020-00-29, if nothing is set replace with a null string
        
$removedates = array("year-month-day hh:mm","year","month","day"," hh:mm","hh","mm");
        
$subdates = array("","0000","00","00","","00","");
        
$val str_replace($removedates,$subdates,$val);
        }

    return 
$val;
    }

This article was last updated 24th November 2020 06:05 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.