Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

SmartyValidate - isDate: Does it work at all?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sguillory6
Smarty Rookie


Joined: 20 Feb 2006
Posts: 17

PostPosted: Mon Feb 20, 2006 6:06 pm    Post subject: SmartyValidate - isDate: Does it work at all? Reply with quote

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
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Feb 20, 2006 7:20 pm    Post subject: Reply with quote

sample code / template ?
Back to top
View user's profile Send private message Visit poster's website
sguillory6
Smarty Rookie


Joined: 20 Feb 2006
Posts: 17

PostPosted: Mon Feb 20, 2006 8:31 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
sguillory6
Smarty Rookie


Joined: 20 Feb 2006
Posts: 17

PostPosted: Mon Feb 20, 2006 8:52 pm    Post subject: Time to get ready for PHP 5.1! Reply with quote

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
View user's profile Send private message Send e-mail
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Mon Feb 20, 2006 9:10 pm    Post subject: Reply with quote

The beauty of the SmartyValidate system, is that you have the freedom to create you own validators...
_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
sguillory6
Smarty Rookie


Joined: 20 Feb 2006
Posts: 17

PostPosted: Mon Feb 20, 2006 9:16 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Mon Feb 20, 2006 9:30 pm    Post subject: Reply with quote

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.
_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Feb 20, 2006 9:35 pm    Post subject: Re: Time to get ready for PHP 5.1! Reply with quote

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
View user's profile Send private message Visit poster's website
sguillory6
Smarty Rookie


Joined: 20 Feb 2006
Posts: 17

PostPosted: Mon Feb 20, 2006 9:44 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
sguillory6
Smarty Rookie


Joined: 20 Feb 2006
Posts: 17

PostPosted: Mon Feb 20, 2006 9:47 pm    Post subject: Reply with quote

[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
View user's profile Send private message Send e-mail
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Mon Feb 20, 2006 10:30 pm    Post subject: Reply with quote

Haha, low blow, i suppose you're right... I always assume and you know what that means Wink

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Feb 20, 2006 11:29 pm    Post subject: Reply with quote

FYI, there is an example on validating dates in the README, see the example using makeDate.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP