View previous topic :: View next topic |
Author |
Message |
sguillory6 Smarty Rookie
Joined: 20 Feb 2006 Posts: 17
|
Posted: Mon Feb 20, 2006 6:06 pm Post subject: SmartyValidate - isDate: Does it work at all? |
|
|
I just got SmartyValidate installed and working, and the sample application from documentation works fine except for the isDate validator. It doesn't matter what I type into the text field validated by this validator, it always passes validation. Is there some trick to getting this validator to work?
I am going to look at the source for it, but thought I'd post here to get some parallelism going.
Stan |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 20, 2006 7:20 pm Post subject: |
|
|
sample code / template ? |
|
Back to top |
|
sguillory6 Smarty Rookie
Joined: 20 Feb 2006 Posts: 17
|
Posted: Mon Feb 20, 2006 8:31 pm Post subject: |
|
|
mohrt wrote: | sample code / template ? |
Uh, the one from the readme posted at:
http://www.phpinsider.com/php/code/SmartyValidate/
I have now written code to exercise every canned validate that ships with
SmartyValidate and the seem to work as advertise. However, just literally copying and pasting the example from the above link results in a page where every validatator on the page works except for the "isDate" one. I can type in anything, i.e. :"*39L*&&%#)*(" or "79438(*)(#*&Q", and it passes as a date.
I am using SmartyValidate 2.6 with Smarty 2.6.12.
Stan |
|
Back to top |
|
sguillory6 Smarty Rookie
Joined: 20 Feb 2006 Posts: 17
|
Posted: Mon Feb 20, 2006 8:52 pm Post subject: Time to get ready for PHP 5.1! |
|
|
Looks like it's a PHP 5.1 issue. The strtotime function went from returning -1 in 5.0 and previous to returning FALSE in 5.1. I have attached a patch. By the way, this is a pretty weakass isDate validator. Is there any work going on on a better one? I seriously doubt that the things that strtotime accepts as valid is what people are expecting when the ask for date validation. Q: When do you plan to pay?
A: Next Thursday :*)
validate_criteria.isDate.php
41c41
< return strtotime($value) != -1;
---
> return strtotime($value) != FALSE; |
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
|
Back to top |
|
sguillory6 Smarty Rookie
Joined: 20 Feb 2006 Posts: 17
|
Posted: Mon Feb 20, 2006 9:16 pm Post subject: |
|
|
TGKnIght wrote: | The beauty of the SmartyValidate system, is that you have the freedom to create you own validators... |
Oh quite true, I agree. I just wonder how many users of SmartyValidate out there realize that "Last Monday" is a valid date?
Stan |
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 20, 2006 9:35 pm Post subject: Re: Time to get ready for PHP 5.1! |
|
|
sguillory6 wrote: | Looks like it's a PHP 5.1 issue. The strtotime function went from returning -1 in 5.0 and previous to returning FALSE in 5.1. I have attached a patch. By the way, this is a pretty weakass isDate validator. Is there any work going on on a better one? I seriously doubt that the things that strtotime accepts as valid is what people are expecting when the ask for date validation. Q: When do you plan to pay?
A: Next Thursday :*)
validate_criteria.isDate.php
41c41
< return strtotime($value) != -1;
---
> return strtotime($value) != FALSE; |
CVS has been patched with a version that handles both PHP 4 and 5. |
|
Back to top |
|
sguillory6 Smarty Rookie
Joined: 20 Feb 2006 Posts: 17
|
Posted: Mon Feb 20, 2006 9:44 pm Post subject: |
|
|
TGKnIght wrote: | Well, actually I recall looking around and seeing a natural date selector.. one where you could choose Next Thursday as the date or whatever...
When you actually put it all into practice though, are you going to want to have the user type in the date in a text field??
I use html_select_date for my date fields and would never run into this specific issue. |
Fair enough. Throwing out html_select_date is a bit of low blow though, because it assumes a "more than absolute beginner" familiarity with Smarty. However, I guess if you are messing around with SmartyValidate, all gloves are off.
I work for the airline industry which is formally known as the "Scheduled Airline Industry", so I am used to date validation consisting of a set of regular expessions that would make the hardest of of Unix veterans wet thier pants.
Having said all that, I have got to hand it to the SmartyValidate guys. I am coming from an enterprise C++/J2EE background where I have to get a one-off client up and going on a PHP/MySQL platform. My biggest issue has just been finding out how to do stuff that I take for granted in the J2EE world. A lot of clowns have written useless articles on form validation in PHP. You guys are the first thing I came across which met my expectations and got the job done.
A huge fan,
Stan |
|
Back to top |
|
sguillory6 Smarty Rookie
Joined: 20 Feb 2006 Posts: 17
|
Posted: Mon Feb 20, 2006 9:47 pm Post subject: |
|
|
[quote="sguillory6"] TGKnIght wrote: | Well, actually I recall looking around and seeing a natural date selector.. one where you could choose Next Thursday as the date or whatever...
When you actually put it all into practice though, are you going to want to have the user type in the date in a text field??
I use html_select_date for my date fields and would never run into this specific issue. |
Oh By the way, I just wanted mention that I would never let users enter dates by hand either. It's just that when that specific case failed in the presented example, I started to get that feeling, ". . . not another f*cked up piece of crap. . ". I quickly got passed that feeling. Good job guys,
Stan |
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
Posted: Mon Feb 20, 2006 10:30 pm Post subject: |
|
|
Haha, low blow, i suppose you're right... I always assume and you know what that means
You're right though, getting {html_select_date} to work with isDate was a PITA, considering that you need to combine the field value etc etc...
There are cases where my example wouldn't fit... such as if someone were to use a JavaScript calendar that filled in a text input field... Then you definately would want the validation to check formatting and such incase the meddling user went in and altered the date after using the calendar selector.
Either way tho, it is good that you found the change in the functions return value, because it seems that users on 5.1 (such as myself) would have everything validated no matter what it was. _________________ Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 20, 2006 11:29 pm Post subject: |
|
|
FYI, there is an example on validating dates in the README, see the example using makeDate. |
|
Back to top |
|
|