38 require_once realpath(dirname(__FILE__)).
"/../field_renderers.inc";
57 $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
61 $this->parent->validator->add(
new RequiredValidator(
"{$field}_mm",
"$label Month"));
62 $this->parent->validator->add(
new RequiredValidator(
"{$field}_dd",
"$label Day"));
63 $this->parent->validator->add(
new RequiredValidator(
"{$field}_yy",
"$label Year"));
66 if ($this->minimumAge)
68 $this->parent->validator->add(
new MinimumAgeValidator($field, $label, $this->minimumAge, $this->minimumAgeMessage));
74 $this->minimumAge = $min;
75 $this->minimumAgeMessage = $message ? $message :
"You must be at least {$min} years of age";
85 $obj = $this->parent->data;
88 $obj = $obj->findSubObject($field);
91 $month = intval($obj->format(
"{{$field}:n}"));
92 $day = intval($obj->format(
"{{$field}:j}"));
93 $year = intval($obj->format(
"{{$field}:Y}"));
95 trace(
"** Month: $month, Day: $day, Year: $year, Field: {$obj->$field}", 3);
98 $default = !$month ?
" selected" :
"";
100 echo
"<select id='{$this->parent->id}_{$field}_mm' type='text' name='{$field}_mm'><option value='' disabled {$default}>Month</option>";
102 for($i = 1; $i <= 12; ++$i)
104 $mm =
new DateTime(
"{$i}/1/1971");
105 $monthName = $mm->format(
"M");
106 option($i, $monthName, $month);
109 $default = !$day ?
" selected" :
"";
110 echo
"</select> / <select id='{$this->parent->id}_{$field}_dd' type='text' name='{$field}_dd'><option value='' disabled {$default}>Day</option>";
112 for($i = 1; $i < 32; ++$i)
117 $default = !$year ?
" selected" :
"";
118 echo
"</select> / <select id='{$this->parent->id}_{$field}_yy' type='text' name='{$field}_yy'><option value='' disabled {$default}>Year</option>";
120 for($i = date(
'Y'); $i >= 1900; --$i)
142 echo $this->
format($this->parent->data->get($field));
154 trace(
"Preprocessing data of birth", 3);
160 if ($mm < 10) $mm =
"0{$mm}";
161 if ($dd < 10) $dd =
"0{$dd}";
163 $dob =
"$yy-$mm-$dd";
165 trace(
"** Preprocessing date of birth: $dob", 3);
167 $this->parent->data->set($field, $dob);
Field renderer for date of birth data fields.
renderSearchField($field, $mode)
FieldRenderers must override this method to provide the HTML implementation of the control displayed ...
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
setMinimumAge($min, $message="")
DateFieldRenderer(&$parent)
addValidatorsToForm($field, $required=false)
This method is called by the AutoForm to add any default input validators that are required by the Fi...
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
renderSearchScript($field, $mode)
FieldRenderers can override this method to provide any Javascript that the control requires when bein...
static format($date, $template="")
FieldRenderer is the abstract base class for all FieldRenderers.
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_endField($field)
Internal method to generate the closing HTML for the field.
FieldRenderer($parent)
Constructor.
AgeRangeValidator can be used with DateOfBirth fields.
checkNumeric($p)
Security helper function.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
option($value, $text, $sel="")
Write out an option tag, marking as selected if applicable.