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: isCCExpDate validation doesn't work!?

 
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 -> Add-ons
View previous topic :: View next topic  
Author Message
davemenc
Smarty Rookie


Joined: 18 Mar 2005
Posts: 6

PostPosted: Fri Mar 18, 2005 7:15 am    Post subject: SmartyValidate: isCCExpDate validation doesn't work!? Reply with quote

I'm working with the example in the README file and I can't get the thing to agree that ANY date is valid for credit card expiration field.

The code looks to me like it should accept a valid month, a non numeric character, and a valid year, provided the date represented by the month+year is in the future.

But I've tried "08/08" and "8/2006" and a lot more besides and it never seems to agree that I've got a valid date in the future.

Please show me the error of my ways... I will be happy if someone can show me just one string that it will accept.

Dave
Back to top
View user's profile Send private message
mux
Smarty n00b


Joined: 18 Mar 2005
Posts: 2

PostPosted: Fri Mar 18, 2005 7:33 am    Post subject: Reply with quote

I couldn't get that to work, either.

I really like the approach SmartyValidate is using, and I'm thinking about using it, but the fact that the example doesn't work does not instill confidence ...
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Mar 18, 2005 2:31 pm    Post subject: Reply with quote

Its a bug. Here is the fix:

Code:
function smarty_validate_criteria_isCCExpDate($value, $empty, &$params, &$formvars) {
    if(strlen($value) == 0)
        return $empty;

    if(!preg_match('!^(\d+)\D+(\d+)$!', $value, $_match))
        return false;

    $_month = $_match[1];
    $_year = $_match[2];
   
    if(strlen($_year) == 2)
        $_year = substr(date('Y', time()),0,2) . $_year;

    $_month = (int) $_month;
    $_year = (int) $_year;
   
   if($_month < 1 || $_month > 12)
      return false;
   if(date('Y',time()) > $_year)
      return false;
   
   if(date('Y',time()) == $_year && date('m', time()) > $_month)
      return false;

   return true;

}
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: Fri Mar 18, 2005 2:43 pm    Post subject: Reply with quote

mux wrote:
I couldn't get that to work, either.

I really like the approach SmartyValidate is using, and I'm thinking about using it, but the fact that the example doesn't work does not instill confidence ...


There are a lot of folks using SmartyValidate successfully. I think the ccExpDate criteria is one that no one has put to use yet (including myself) and consequently, no one has reported the problem until now.

btw, the CVS version of SmartyValidate takes a little different approach, moving the validation criteria to the PHP side, leaving only presentation (error messages) in the template.
Back to top
View user's profile Send private message Visit poster's website
mux
Smarty n00b


Joined: 18 Mar 2005
Posts: 2

PostPosted: Fri Mar 18, 2005 5:44 pm    Post subject: Reply with quote

In the CVS version, can you still do validation in the Smarty template, or is the PHP-side method replacing that?

I'm going to keep SmartyValidate in mind; however, I think I need something more mature for my current project.

Thanks for your help!
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Mar 18, 2005 6:08 pm    Post subject: Reply with quote

Either way should work fine.
Back to top
View user's profile Send private message Visit poster's website
davemenc
Smarty Rookie


Joined: 18 Mar 2005
Posts: 6

PostPosted: Fri Mar 18, 2005 8:08 pm    Post subject: Reply with quote

[quote="mohrt"]Its a bug. Here is the fix:
snip...[/quote]

Aha! So it was doing a string comparison instead of a numeric comparison. I looked and looked but just couldn't find it! It was driving me CRAZY! :)

Thanks much

Dave
Back to top
View user's profile Send private message
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 -> Add-ons 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