function _clientside_validation_set_date in Clientside Validation 7
1 call to _clientside_validation_set_date()
- clientside_validation_regular in clientside_validation_form/
clientside_validation_form.module
File
- ./
clientside_validation.module, line 1303 - Add client side validation to forms.
Code
function _clientside_validation_set_date($name, $title, $format, &$js_rules, $message = "") {
$title = _clientside_validation_set_title($title);
$splitter = '/';
if (strpos($format, '.') !== FALSE) {
$splitter = '.';
}
elseif (strpos($format, ' ') !== FALSE) {
$splitter = ' ';
}
elseif (strpos($format, '-') !== FALSE) {
$splitter = '-';
}
$parts = explode($splitter, $format);
$daypos = array_search('d', $parts) === FALSE ? array_search('j', $parts) : array_search('d', $parts);
foreach (array(
'm',
'M',
'F',
'n',
) as $m) {
$monthpos = array_search($m, $parts);
if ($monthpos !== FALSE) {
break;
}
}
$yearpos = array_search('Y', $parts);
$js_rules[$name]['dateFormat'] = array(
'format' => $format,
'splitter' => $splitter,
'daypos' => $daypos,
'monthpos' => $monthpos,
'yearpos' => $yearpos,
);
$variables = array(
'message' => empty($message) ? 'The value in !title is not a valid date.' : $message,
'placeholders' => empty($message) ? array(
'!title' => $title,
) : array(),
'error_type' => 'date',
'element_name' => $name,
);
$js_rules[$name]['messages']['dateFormat'] = theme('clientside_error', $variables);
}