Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

SmartyValidate 2.9 released
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
mohrt
Administrator


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

PostPosted: Mon Apr 23, 2007 2:55 pm    Post subject: SmartyValidate 2.9 released Reply with quote

2.9 Apr 23, 2007
----------------

* fix bug with multiple validators on a field (mckneisler, monte)
* fix bug with initialization of multiple forms (schildi, monte)
* fix looping on non-numeric index arrays (kayk, monte)


http://www.phpinsider.com/php/code/SmartyValidate/
Back to top
View user's profile Send private message Visit poster's website
IGonza
Smarty Rookie


Joined: 14 Jan 2007
Posts: 17

PostPosted: Tue Sep 04, 2007 10:08 am    Post subject: Reply with quote

Code:

function smarty_validate_criteria_isURL($value, $empty, &$params, &$formvars) {
    if(strlen($value) == 0)
        return $empty;       
    return preg_match('!^http(s)?://[\w-]+\.?[\w-]+(\S+)?$!i', $value);
}


This function doesn't work correct for $value == http://www or http://aaa
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Sep 04, 2007 4:25 pm    Post subject: Reply with quote

Is that a valid URL?

If you think so, this would probably work for you:

Code:
return preg_match('!^http(s)?://[\w-]+\.?[\w-]*(\S+)?$!i', $value);
Back to top
View user's profile Send private message Visit poster's website
IGonza
Smarty Rookie


Joined: 14 Jan 2007
Posts: 17

PostPosted: Tue Sep 04, 2007 4:54 pm    Post subject: Reply with quote

I mean
Code:

preg_match('!^http(s)?://[\w-]+\.?[\w-]+(\S+)?$!i', $value);

returns 1 for http://www .


I use
Code:

return preg_match("/^https?:\/\/([\w-]+\.)+[a-zA-Z]{2,7}$/i",$value);
Back to top
View user's profile Send private message
ZuqR
Smarty Rookie


Joined: 01 Dec 2007
Posts: 6

PostPosted: Tue Feb 12, 2008 8:49 pm    Post subject: Reply with quote

Is this a 'live validator' like AJAX? Or does the page reload?
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


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

PostPosted: Tue Feb 12, 2008 9:03 pm    Post subject: Reply with quote

By default it reloads the page, but you could modify it to work through AJAX pretty easily so long as you pass the PHP session along with it.
Back to top
View user's profile Send private message Visit poster's website
psycco
Smarty Rookie


Joined: 08 Aug 2006
Posts: 8

PostPosted: Sun Feb 17, 2008 7:12 pm    Post subject: Reply with quote

hello mohrt,

sorry its my failure to spam your thread:

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=12759


Last edited by psycco on Sun Feb 17, 2008 11:48 pm; edited 2 times in total
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sun Feb 17, 2008 10:40 pm    Post subject: Reply with quote

Firstly, don't hijack old forum threads, start a new one. Second, it's not possible to see what is wrong with the info you supplied. We need to see all of the PHP code and template code involved. Follow the working examples that come with SmartyValidate FIRST, then deviate from that.
Back to top
View user's profile Send private message Visit poster's website
anorgan
Smarty n00b


Joined: 18 Oct 2008
Posts: 4

PostPosted: Sat Oct 18, 2008 11:35 pm    Post subject: Reply with quote

This is a good add-on
Back to top
View user's profile Send private message
DumKopf
Smarty Rookie


Joined: 24 Sep 2007
Posts: 8

PostPosted: Wed Oct 29, 2008 3:07 am    Post subject: Reply with quote

I had to modify the isDate plugin so it checks for valid dates eg. 30-02-2008 doesn't exit, but isDate thinks it is true.

Code:
function smarty_validate_criteria_isDate($value, $empty, &$params, &$formvars) {
    list($yy,$mm,$dd)=explode("-",$value);

    if(strlen($value) == 0)
        return $empty;
    if(checkdate($mm,$dd,$yy)){$_ret = strtotime($value);}else{$_ret = false;};
    return $_ret != -1 && $_ret !== false;
}


I'm sure it can be cleaned up, but you get the gist.
Back to top
View user's profile Send private message
IGonza
Smarty Rookie


Joined: 14 Jan 2007
Posts: 17

PostPosted: Mon Feb 02, 2009 2:20 pm    Post subject: Reply with quote

Hi,

there are 2 validators :

Code:


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

    return preg_match('!^\d+(\.\d+)?$!', $value);
}

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

    return preg_match('!^\d+\.\d+?$!', $value);
}


Both of them return false for negative number. I think it's not correct.
You should use something like :
Code:

return preg_match('!^\-?\d+(\.\d+)?$!', $value);
Back to top
View user's profile Send private message
cferry
Smarty Rookie


Joined: 17 Jun 2009
Posts: 9

PostPosted: Wed Jun 17, 2009 3:00 pm    Post subject: Little patch for selectbox multiple and isRegExp Reply with quote

Hi !
1) you have a selectbox multiple and no item selected
2) you have a smartyValidate with isRegExp

you may have index error on lines 185 and 199 because no data are send. and $formvars[$_field] does not exists. you have to add isset()

this patch correct this problem :
Code:

--- SmartyValidate.class.php   2009-06-17 16:44:22.000000000 +0200
+++ SmartyValidate.class.php   2009-06-17 16:42:55.000000000 +0200
@@ -182,7 +182,7 @@
                         }
                     }
                     
-                    if(is_array($formvars[$_field]) && !$_trans_on_array) {
+                    if(isset($formvars[$_field]) && is_array($formvars[$_field]) && !$_trans_on_array) {
                         if(isset($_field_key)) {
                             // only apply to given key
                             if(($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field][$_field_key], $_sess[$_key], $formvars, $form)) !== false)
@@ -196,7 +196,7 @@
                             }
                         }
                     } else {
-                         if(($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form)) !== false)
+                         if(isset($formvars[$_field]) && ($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form)) !== false)
                              $formvars[$_field] = $_new_val;
                     }
                 }


TPL
Code:

<select id="primary_domain_VhostAbstract" name="primary_domain_VhostAbstract[]" multiple="multiple"  >                  
<option label="" value="1"  >1</option>               
<option label="" value="2"  >2</option>
</select>

{validate form="primary_domain"  id="validation_primary_domain_VhostAbstract" message=#primary_domain_VhostAbstracts_validatemsg#}



PHP
Code:

SmartyValidate::register_validator( 'validation_primary_domain_VhostAbstract' , 'primary_domain_VhostAbstract:!(^[_0-9]*$)!' , 'isRegExp' , TRUE , FALSE , 'trim', 'primary_domain' );
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Jun 17, 2009 4:00 pm    Post subject: Reply with quote

committed changes to CVS, thanks.
Back to top
View user's profile Send private message Visit poster's website
fuhraih
Smarty n00b


Joined: 11 Aug 2009
Posts: 3

PostPosted: Tue Aug 11, 2009 1:06 pm    Post subject: Reply with quote

Hi !
I have a question about how to use this pluggin with multi language site.
I use a config file (one file per language) in order to have several translations of my website. Then, in the template I use {#myConfigVariable#} to put the phrase in the right language.
How can I use this config variable in my Validate message in order to show the message in the user language?
thanks
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Aug 11, 2009 1:26 pm    Post subject: Reply with quote

You can use the alternate config syntax of $smarty.config.myConfigVar in the params.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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