[Solar-talk] Date Fields

Paul M Jones pmjones at paul-m-jones.com
Fri May 2 10:51:05 CDT 2008


On May 2, 2008, at 11:36 , Kilbride, James P. wrote:
> So, when putting date fields on forms what do people like to use for  
> the format and are there any helpers that people have for dates that  
> make it easier for people to enter them 'correctly'?
>

Just added some stuff in SVN earlier this week (late last week?) that  
helps with this.

First, the validate and sanitize filters for date/time/timestamp now  
additionally take array values, where the keys map to date() format  
keys (Y, m, d, H, i, s).  Validate will attempt to validate an array  
with those keys, and sanitize will take an array with those keys and  
convert it into an ISO string.  (This is in addition to the previously  
existing behavior of validating and sanitizing strings.)

Once that was in place, I added view helpers formDate, formTime, and  
formTimestamp().  These present the temporal values as a series of  
select/options, so you can pick the year, month, day, hour, and minute  
separately.  They return the individual values as part of an array, so  
the validate and sanitize filters will pick them up and handle them  
correctly.

You can see some of the relevant code here:

   <http://solarphp.com/svn/trunk/Solar/Filter/ValidateIsoTimestamp.php>

   <http://solarphp.com/svn/trunk/Solar/Filter/SanitizeIsoTimestamp.php>

   <http://solarphp.com/svn/trunk/Solar/View/Helper/FormTimestamp.php>

(The "date" and "time" versions of these are highly similar.)

Hope this helps, please let me know if it does not.


-- pmj


More information about the Solar-talk mailing list