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: Multiple Fields get ignored by validation

 
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
tdmf
Smarty Rookie


Joined: 24 Jul 2006
Posts: 21

PostPosted: Fri Sep 08, 2006 8:23 pm    Post subject: SmartyValidate: Multiple Fields get ignored by validation Reply with quote

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


Joined: 24 Jul 2006
Posts: 21

PostPosted: Mon Sep 11, 2006 8:53 am    Post subject: Reply with quote

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


Joined: 24 Jul 2006
Posts: 21

PostPosted: Tue Sep 12, 2006 8:16 am    Post subject: Reply with quote

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


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

PostPosted: Tue Sep 12, 2006 1:19 pm    Post subject: Reply with quote

I don't think isFloat can take multiple fields. You can write custom validators to do whatever behavior you want, FYI.
Back to top
View user's profile Send private message Visit poster's website
tdmf
Smarty Rookie


Joined: 24 Jul 2006
Posts: 21

PostPosted: Tue Sep 12, 2006 3:12 pm    Post subject: Reply with quote

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


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

PostPosted: Tue Sep 12, 2006 5:15 pm    Post subject: Reply with quote

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


Joined: 24 Jul 2006
Posts: 21

PostPosted: Wed Sep 13, 2006 1:01 pm    Post subject: Reply with quote

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


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

PostPosted: Wed Sep 13, 2006 1:39 pm    Post subject: Reply with quote

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


Joined: 24 Jul 2006
Posts: 21

PostPosted: Thu Sep 14, 2006 11:13 am    Post subject: Reply with quote

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
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