Welcome Guest, Not a member yet? Register   Sign In
Function set_value() not working as expected
#20

[eluser]jbreitweiser[/eluser]
Fixed extra space in last return statement.

Replace the set_value, set_select, set_radio, and set_checkbox in the /system/libraries/Form_validation.php file. Basically if the form validator does not have the value, the code checks the input class.

Code:
/**
     * Get the value from a form
     *
     * Permits you to repopulate a form field with the value it was submitted
     * with, or, if that value doesn't exist, with the default
     *
     * @access    public
     * @param    string    the field name
     * @param    string
     * @return    void
     */    
    function set_value($field = '', $default = '')
    {
        if ( ! isset($this->_field_data[$field]))
        {
            if( $this->CI->input->post($field)===FALSE)
            {
                return $default;
            }
            else
            {
                return $this->CI->input->post($field);
            }
        }
        
        return $this->_field_data[$field]['postdata'];
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Set Select
     *
     * Enables pull-down lists to be set to the value the user
     * selected in the event of an error
     *
     * @access    public
     * @param    string
     * @param    string
     * @return    string
     */    
    function set_select($field = '', $value = '', $default = FALSE)
    {        
        return $this->set_value_array($field, $value, ' selected="selected"', $default);
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Set Radio
     *
     * Enables radio buttons to be set to the value the user
     * selected in the event of an error
     *
     * @access    public
     * @param    string
     * @param    string
     * @return    string
     */    
    function set_radio($field = '', $value = '', $default = FALSE)
    {
        return $this->set_value_array($field, $value, ' selected="selected"', $default);
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Set Checkbox
     *
     * Enables checkboxes to be set to the value the user
     * selected in the event of an error
     *
     * @access    public
     * @param    string
     * @param    string
     * @return    string
     */    
    function set_checkbox($field = '', $value = '', $default = FALSE)
    {
        return $this->set_value_array($field, $value, ' checked="checked"', $default);
    }
    
    function set_value_array($field = '', $value = '', $default_value = '' ,$default = FALSE){
        if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
        {
            if( ! ($this->CI->input->post($field) === FALSE))
            {
                $field = $this->CI->input->post($field);
            }
            else
            {
                if ($default === TRUE AND count($this->_field_data) === 0)
                {
                    return $default_value;
                }
                return '';
            }
        }
        else
        {
        $field = $this->_field_data[$field]['postdata'];
        }
        
        if (is_array($field))
        {
            if ( ! in_array($value, $field))
            {
                return '';
            }
        }
        else
        {
            if (($field == '' OR $value == '') OR ($field != $value))
            {
                return '';
            }
        }
            
        return $default_value;
    }


Messages In This Thread
Function set_value() not working as expected - by El Forum - 11-11-2008, 09:51 AM
Function set_value() not working as expected - by El Forum - 11-11-2008, 10:22 AM
Function set_value() not working as expected - by El Forum - 11-11-2008, 12:34 PM
Function set_value() not working as expected - by El Forum - 11-12-2008, 01:20 PM
Function set_value() not working as expected - by El Forum - 11-23-2008, 10:16 PM
Function set_value() not working as expected - by El Forum - 11-23-2008, 10:47 PM
Function set_value() not working as expected - by El Forum - 11-24-2008, 12:16 AM
Function set_value() not working as expected - by El Forum - 01-19-2009, 10:30 AM
Function set_value() not working as expected - by El Forum - 02-08-2009, 12:21 AM
Function set_value() not working as expected - by El Forum - 02-08-2009, 04:32 AM
Function set_value() not working as expected - by El Forum - 02-08-2009, 10:16 AM
Function set_value() not working as expected - by El Forum - 02-08-2009, 11:59 AM
Function set_value() not working as expected - by El Forum - 02-24-2009, 11:52 AM
Function set_value() not working as expected - by El Forum - 07-15-2009, 10:45 AM
Function set_value() not working as expected - by El Forum - 07-15-2009, 12:33 PM
Function set_value() not working as expected - by El Forum - 11-10-2009, 11:42 AM
Function set_value() not working as expected - by El Forum - 11-10-2009, 12:08 PM
Function set_value() not working as expected - by El Forum - 12-13-2009, 09:43 PM
Function set_value() not working as expected - by El Forum - 01-01-2010, 11:42 PM
Function set_value() not working as expected - by El Forum - 01-02-2010, 09:39 AM
Function set_value() not working as expected - by El Forum - 05-03-2010, 12:45 AM
Function set_value() not working as expected - by El Forum - 06-17-2010, 03:34 AM
Function set_value() not working as expected - by El Forum - 06-25-2010, 06:32 AM
Function set_value() not working as expected - by El Forum - 08-17-2010, 03:08 PM
Function set_value() not working as expected - by El Forum - 09-13-2010, 09:38 PM
Function set_value() not working as expected - by El Forum - 09-23-2010, 04:33 AM
Function set_value() not working as expected - by El Forum - 10-12-2010, 01:33 PM
Function set_value() not working as expected - by El Forum - 12-15-2010, 02:08 PM
Function set_value() not working as expected - by El Forum - 01-19-2011, 02:30 AM
Function set_value() not working as expected - by El Forum - 04-20-2011, 09:22 AM
Function set_value() not working as expected - by El Forum - 05-04-2011, 06:30 AM
Function set_value() not working as expected - by El Forum - 05-05-2011, 03:19 PM
Function set_value() not working as expected - by El Forum - 06-21-2011, 01:12 AM
Function set_value() not working as expected - by El Forum - 08-05-2011, 05:03 PM
Function set_value() not working as expected - by El Forum - 08-05-2011, 05:14 PM
Function set_value() not working as expected - by El Forum - 04-03-2012, 10:18 AM
Function set_value() not working as expected - by El Forum - 05-14-2012, 01:50 PM
Function set_value() not working as expected - by El Forum - 07-28-2012, 01:42 AM
Function set_value() not working as expected - by El Forum - 07-28-2012, 02:22 AM
Function set_value() not working as expected - by El Forum - 08-26-2012, 12:58 PM
Function set_value() not working as expected - by El Forum - 08-26-2012, 01:16 PM
Function set_value() not working as expected - by El Forum - 08-26-2012, 11:07 PM
Function set_value() not working as expected - by El Forum - 08-27-2012, 10:07 AM
Function set_value() not working as expected - by El Forum - 08-27-2012, 07:08 PM
Function set_value() not working as expected - by El Forum - 02-13-2014, 10:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB