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

[SmartyValidate][BUG] Validating arrays

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
hayk
Smarty Rookie


Joined: 23 Jun 2006
Posts: 5
Location: ExUSSR

PostPosted: Mon Mar 05, 2007 3:30 pm    Post subject: [SmartyValidate][BUG] Validating arrays Reply with quote

I have a group of text inputs in the form

Code:
<input name="cost[1]" value="1" type="text" />
<input name="cost[4]" value="4" type="text" />
<input name="cost[6]" value="6" type="text" />
<input name="cost[5]" value="5" type="text" />
<input name="su" value="" type="text" />


After form submiting I have an array
Quote:
$_POST[cost] => Array
(
[1] => 1
[4] => 4
[5] => 5
[6] => 6
)

SmartyValidate::register_validator('cost', 'cost[]', 'notEmpty', false, true, 'trim');

But after transform function ( trim() ) I have another array:
Quote:
$_POST[cost] => Array
(
[0] =>
[1] => 1
[4] => 4
[5] => 5
[6] => 6
)


I check the code and I think it would be better use this:
Code:
for($_x = 0, $_y = count($formvars[$_field]); $_x < $_y; $_x++) {
    if(($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field][$_x], $_sess[$_key], $formvars, $form)) !== false)
        $formvars[$_field][$_x] = $_new_val;
}


instead of:
Code:
foreach ($formvars[$_field] as $_fv_key => $_fv_value) {
    if(($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field][$_fv_key], $_sess[$_key], $formvars, $form)) !== false)
        $formvars[$_field][$_x] = $_new_val;
}


And this:
Code:
for($_x = 0, $_y = count($formvars[$_field]); $_x < $_y; $_x++) {
    if(! $_sess[$_key]['valid'] = SmartyValidate::_is_valid_criteria($_val['criteria'], $formvars[$_field][$_x], $_empty, $_sess[$_key], $formvars, $form)) {
        // found invalid array element, exit for loop
        break;
    }
}


instead of:
Code:
foreach ($formvars[$_field] as $_fv_key => $_fv_value) {
    if(! $_sess[$_key]['valid'] = SmartyValidate::_is_valid_criteria($_val['criteria'], $formvars[$_field][$_fv_key], $_empty, $_sess[$_key], $formvars, $form)) {
        // found invalid array element, exit for loop
        break;
    }
}


Sorry for my English.
If my description is not clear, I'll try to explain again.
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
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