View previous topic :: View next topic |
Author |
Message |
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 23, 2007 2:55 pm Post subject: SmartyValidate 2.9 released |
|
|
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 |
|
IGonza Smarty Rookie
Joined: 14 Jan 2007 Posts: 17
|
Posted: Tue Sep 04, 2007 10:08 am Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Sep 04, 2007 4:25 pm Post subject: |
|
|
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 |
|
IGonza Smarty Rookie
Joined: 14 Jan 2007 Posts: 17
|
Posted: Tue Sep 04, 2007 4:54 pm Post subject: |
|
|
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 |
|
ZuqR Smarty Rookie
Joined: 01 Dec 2007 Posts: 6
|
Posted: Tue Feb 12, 2008 8:49 pm Post subject: |
|
|
Is this a 'live validator' like AJAX? Or does the page reload? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Feb 12, 2008 9:03 pm Post subject: |
|
|
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 |
|
psycco Smarty Rookie
Joined: 08 Aug 2006 Posts: 8
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Feb 17, 2008 10:40 pm Post subject: |
|
|
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 |
|
anorgan Smarty n00b
Joined: 18 Oct 2008 Posts: 4
|
Posted: Sat Oct 18, 2008 11:35 pm Post subject: |
|
|
This is a good add-on |
|
Back to top |
|
DumKopf Smarty Rookie
Joined: 24 Sep 2007 Posts: 8
|
Posted: Wed Oct 29, 2008 3:07 am Post subject: |
|
|
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 |
|
IGonza Smarty Rookie
Joined: 14 Jan 2007 Posts: 17
|
Posted: Mon Feb 02, 2009 2:20 pm Post subject: |
|
|
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 |
|
cferry Smarty Rookie
Joined: 17 Jun 2009 Posts: 9
|
Posted: Wed Jun 17, 2009 3:00 pm Post subject: Little patch for selectbox multiple and isRegExp |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jun 17, 2009 4:00 pm Post subject: |
|
|
committed changes to CVS, thanks. |
|
Back to top |
|
fuhraih Smarty n00b
Joined: 11 Aug 2009 Posts: 3
|
Posted: Tue Aug 11, 2009 1:06 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Aug 11, 2009 1:26 pm Post subject: |
|
|
You can use the alternate config syntax of $smarty.config.myConfigVar in the params. |
|
Back to top |
|
|