Welcome Guest, Not a member yet? Register   Sign In
Is this a CI 1.7 Form validation Helper BUG?
#1

[eluser]mindprojects[/eluser]
All right guys,i'm not pretty sure,but using the new form validation functions(eg. set_select)something changed from previous version(1.6.3) and i'm not sure if it's a small bug.
What i was doing to repopulate from select boxes in 1.7,while using pagination was :

1) set form data in POST values(eg $_POST['select name'] = selected value
2) set $this->validation->set_select('form_name','option value') into the select element;

This trick was working till 1.6.3 release,as it should be,but bothing to do with the new 1.7 set_select.

Then i discovered the problem:
This is the code from form_helper
Code:
function set_select($field = '', $value = '', $default = FALSE)
    {
        $OBJ =& _get_validation_object();


        if ($OBJ === FALSE)
        {
            if ( ! isset($_POST[$field]))
            {
                if (count($_POST) === 0)
                {
                    return ' selected="selected"';
                }
                return '';
            }

I simply changed this into this:
Code:
function set_select($field = '', $value = '', $default = FALSE)
    {
        $OBJ =& _get_validation_object();


        if ($OBJ)
        {
            if ( ! isset($_POST[$field]))
            {
                if (count($_POST) === 0)
                {
                    return ' selected="selected"';
                }
                return '';
            }

I would like someone to reply for this,
thanks
Marco
#2

[eluser]dimethroxy[/eluser]
thanks you for this! this actually fixed the set_select
#3

[eluser]scottzirkel[/eluser]
I'm having the same problem in 1.7.1. I tried your fix, but I got a function on non-object error with the $OBJ object.

I fixed it by changing this line in form_helper.php:

Code:
if (count($_POST) === 0)

to this:

Code:
if(!empty($_POST))

While those SHOULD do the same thing, they are not. Presumably since POST data is set by default.

Hope that helps anyone else looking for solutions.
#4

[eluser]TheFuzzy0ne[/eluser]
I'm not sure what the problem is. However, the check to see if the $OBJ === FALSE is correct. That section of code is run if the validation object has not been instantiated. Please could you post your controller code?




Theme © iAndrew 2016 - Forum software by © MyBB