View previous topic :: View next topic |
Author |
Message |
tdmf Smarty Rookie
Joined: 24 Jul 2006 Posts: 21
|
Posted: Fri Sep 08, 2006 8:23 pm Post subject: SmartyValidate: Multiple Fields get ignored by validation |
|
|
Hello,
i have a strange problem when checking a form with validators that
SmartyValidate::register_validator('v_height', 'y1:y2:y3:y4:y5', 'isFloat', 0, false, null, 'step3');
SmartyValidate::register_validator('v_width', 'x1:x2:x3:x4:x5', 'isFloat', 0, false, null, 'step3');
SmartyValidate::register_validator('v_depth', 'z1:z2:z3:z4:z5', 'isFloat', 0, false, null, 'step3');
as soon as y1,x1 or z1 validate to true, all other fields for the same validator (x1=true -> x2-5 also true) are true.
So when y1,x1 & z1 are true - the whole form will be true......!??!
i want to check each field individually if it validates or not - any hints what i am doing wrong here ?
thank you !!!! |
|
Back to top |
|
tdmf Smarty Rookie
Joined: 24 Jul 2006 Posts: 21
|
Posted: Mon Sep 11, 2006 8:53 am Post subject: |
|
|
Its just a simple table with columns X,Y,Z for "Floats".
The amount of rows is dynamic and i JUST want to check that ALL are floats before the form validates to true !!
Please gimme a short hint, folks. Prob still is that if Row 1 full and validates to true all other rows will validate to true, too.
I need to check each field individually !!!
Thanks for your help !!!! |
|
Back to top |
|
tdmf Smarty Rookie
Joined: 24 Jul 2006 Posts: 21
|
Posted: Tue Sep 12, 2006 8:16 am Post subject: |
|
|
No chance to check dynamicly created fields ?
Code: | SmartyValidate::register_validator('v_height', field1:field2:field3, 'isFloat', 0, false, null, 'step3'); |
Will a validator always be true when just 1 field is true ?!?!?! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Sep 12, 2006 1:19 pm Post subject: |
|
|
I don't think isFloat can take multiple fields. You can write custom validators to do whatever behavior you want, FYI. |
|
Back to top |
|
tdmf Smarty Rookie
Joined: 24 Jul 2006 Posts: 21
|
Posted: Tue Sep 12, 2006 3:12 pm Post subject: |
|
|
So how do i check multiple Fields for the same condition then ?
I can easily register a dynamic amount of validators from within php - but i cannot create dynamic {validate.....} statements from within a SELECT ot FOREACH-Loop !
thanks for your help !!! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Sep 12, 2006 5:15 pm Post subject: |
|
|
You should be able to make a copy of the isEqual validator (one that uses multi params) and rename everything to isFloatMulti, then do your checks on all the params passed into the function, and use isFloatMulti instead of isFloat. |
|
Back to top |
|
tdmf Smarty Rookie
Joined: 24 Jul 2006 Posts: 21
|
Posted: Wed Sep 13, 2006 1:01 pm Post subject: |
|
|
well i tried that but the params-array doesnt only contain my fields but other data like in:
Code: | Array
(
[field] => height1
[field2] => height2
[field3] => height3
[field4] => height4
[field5] => height5
[id] => v_height
[criteria] => isFloatMulti
[message] => enter height
[trim] =>
[empty] => 0
[halt] =>
[transform] =>
[form] => step3
[valid] =>
) |
...so i cant just loop through the params and check for valid data.........
EDIT:
I also cannot call each field "hardcoded" because i dont even know how many fields will be created - its a dynamic amount of fields !
My validator is:
SmartyValidate::register_validator('v_height', $heights, 'isFloatMulti', 0, false, null, 'step3');
...where $heights is a string containing the formfields to be checked like in:
height1:height2:height3:height4:height5 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Sep 13, 2006 1:39 pm Post subject: |
|
|
If they are named similarly you could loop over them:
Code: | foreach($params as $key => $val)
{
if(strpos($key,'height') === 0)
// do validation
} |
|
|
Back to top |
|
tdmf Smarty Rookie
Joined: 24 Jul 2006 Posts: 21
|
Posted: Thu Sep 14, 2006 11:13 am Post subject: |
|
|
Whatever i tried - any effort using $params didnt work for me as only 1 $value would be considered by the function -> so i switched to using $formvars.
Heres my solution:
Code: | function smarty_validate_criteria_checkMyDynamicFields($value, $empty, &$params, &$formvars) {
foreach($formvars as $key => $val) {
if(strpos($key,'height') === 0 || strpos($key,'width') === 0 || strpos($key,'depth') === 0){
if (preg_match('!^\d+\.\d+?$!', $val)){
$matches[] = $val;
}
}
}
if (count($matches) === $formvars['totalfields']*3){
return true;
}
}
|
Thanks a lot for your help - it gave me a deeper insight on SmartyValidate and its logic !!
Greatly appreciated ! |
|
Back to top |
|
|