Welcome Guest, Not a member yet? Register   Sign In
Form Validation Bug
#1

[eluser]lancealtar[/eluser]
So, I think I've found a bug in 1.7.2. I'll try to explain the situation as best I can.

I have a form with two radio inputs and form validation. After the form validates, the controller loads another view with a form and this subsequent form requires validation. The subsequent form also requires radio inputs to have default values set via the "set_radio()" function. After hours of frustration trying to figure out why the second form would not auto populate with "set_radio()", I narrowed it down to the way "Form_validation.php" actually applies " checked=checked" using set_radio.

Lines 790-797 show why this occurs
Code:
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
        {
            if ($default === TRUE AND count($this->_field_data) === 0)
            {
                return ' checked="checked"';
            }
            return '';
        }

The function is looking to see if anything is set in _field_data. Well, if you just used form validation in the same controller that you are calling the subsequent view, of course there will be data loaded into _field_data.

I have found a suitable workaround, for now, by eliminating the "AND count($this->_field_data) === 0" section of the if statement. I believe a more valid solution would be to include a function to remove any _field_data after form validation to allow for subsequent calls to set_radio, set_select, etc.




Theme © iAndrew 2016 - Forum software by © MyBB