Ticket #149 (closed defect: fixed)

Opened 8 years ago

Last modified 8 years ago

Non-required date elements are validated against min and max dates

Reported by: frank.kleine@… Owned by: argh
Priority: highest Milestone: v0.9.0 stable
Component: Element Version: current-cvs
Severity: normal Keywords:
Cc:

Description (last modified by schst) (diff)

When it comes to validation of a submitted form the date element will be validated against minmum and maximal date values, regardless if the element is required or not. In cases where its not required this leads to situations where you get error messages for dates out of this min and max borders which may confuse the user because it was not needed to set the date right.

Solution: in patForms_Element_Date::validateElement() replace

if( $required && is_null( $value ) )

with

if( !$required ) {

return true;

} elseif( $required && is_null( $value ) )

Change History

comment:1 Changed 8 years ago by schst

  • Description modified (diff)
  • Milestone set to v0.9.0 stable

comment:2 Changed 8 years ago by argh

  • Owner changed from argh@… to argh
  • Status changed from new to assigned

if( !$required ) {

return true;

}

would not be sufficient - if a field is not required, you don't have to fill it out. But if you fill it out anyway, the data has to be valid nonetheless. I suggest doing this:

if( !$required && is_null( $value ) ) {

return true;

}

That way the field will be skipped when empty and not required, but will be validated if a value has been set.

comment:3 Changed 8 years ago by argh

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed in SVN. Elements are now only validated when a value has been entered.

Note: See TracTickets for help on using tickets.