Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

sanitize_date_field_input()

Parameters

ColumnTypeDefaultDescription
$date
$validate false

Location

include/resource_functions.php lines 7722 to 7755

Definition

 
function sanitize_date_field_input($date$validate=false)
    {
    
$year_input getval("field_" $date "-y","");
    
$year sprintf("%04d"$year_input);  // Assume CE year
    
if(strlen($year_input)==5) {
        
$year sprintf("%05d"$year_input);  // BCE year has leading -
    
}
    
$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","00");
        
$val str_replace($removedates,$subdates,$val);
        }

    return 
$val;
    }

This article was last updated 17th November 2024 15:05 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.