|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
hayk Smarty Rookie
Joined: 23 Jun 2006 Posts: 5 Location: ExUSSR
|
Posted: Mon Mar 05, 2007 3:30 pm Post subject: [SmartyValidate][BUG] Validating arrays |
|
|
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 |
|
|
|
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
|