Trying to write a combined date tag helper I have come upon the limitation of this method accepting only single string parameters.
To clarify the problem; below is the output of my combined date tag helper:
<input type="text" name="birthdate[day]" id="birthdate_day" />
<input type="text" name="birthdate[month]" id="birthdate_month" />
<input type="text" name="birthdate[year]" id="birthdate_year" />
and in myDateValidator.class.php:
...
public function execute (&$value, &$error)
{
if (is_array($value))
{
if (isset($value['day'] && is_numeric($value['day'])
...
The problem is php throws a notice message and bypasses the below conditional checks while the form is being validated. Which renders the usage of required validation rule for array parameters useless. Not using the required rule also doesn't prevent notice message from appearing since !$datarequired? check is being done after the intolerant strlen($value) == 0 check.
svValidatorManager.class.php (Line 248)
// now for the dirty work
if ($value == null || strlen($value) == 0)
{
if (!$data['required'] || !$force)
{
// we don't have to validate it
$retval = true;
}
else
{
// it's empty!
$error = $data['required_msg'];
$retval = false;
}
}
It may well be modified to accept a parameter array and check if it has any empty member:
// now for the dirty work
if ( $value == null
|| (!is_array($value) && strlen($value) == 0)
|| (is_array($value) && in_array('', $value)) )
{
if (!$data['required'] || !$force)
{
// we don't have to validate it
$retval = true;
}
else
{
// it's empty!
$error = $data['required_msg'];
$retval = false;
}
}