Development

#1911 ([PATCH] input_date_tag validation)

You must first sign up to be able to contribute.

Ticket #1911 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] input_date_tag validation

Reported by: Andrejs.Verza Assigned to: fabien
Priority: major Milestone: 1.1.0
Component: validation Version: 1.0.5
Keywords: sfDateValidator, input_date_tag, validate Cc:
Qualification: Unreviewed

Description

Impossible to validate the input_date_tag's generated date selects with sfDateValidator, because the input_date_tag's generated selects result in a named array in php:

  array ('day', 'month', 'year')

...but sfDateValidator accepts only string-type date.

The solution is to patch sfDateValidator like this:

  protected function getValidDate($value, $culture)
  {
    if (is_array ($value))
    {
      $d = @$value ['day'];
      $m = @$value ['month'];
      $y = @$value ['year'];
    }
    else
    {
      // Use the language culture date format
      $result = $this->getContext()->getI18N()->getDateForCulture($value, $culture);
      list($d, $m, $y) = $result;

      if ($result === null)
      {
        return null;
      }
    }

    // Make sure the date is a valid gregorian calendar date also
    if (!checkdate($m, $d, $y))
    {
      return null;
    }

    return strtotime("$y-$m-$d 00:00");
  }

Change History

06/27/07 18:30:03 changed by Andrejs.Verza

  • summary changed from input_date_tag validation to [PATCH] input_date_tag validation.

06/27/07 18:38:07 changed by Andrejs.Verza

This patch should be compatible with i18n.

The $value is an associative array, therefore it doesn't matter in which order selects are placed on the form.

12/26/07 23:21:35 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.
  • qualification set to Unreviewed.
  • milestone set to 1.1.0.

This won't be fixed in 1.0 because no feature can be added. But this is fixed with the new form framework in symfony 1.1.