• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$_GET and form inconsistancies -- suggestion to engineers.

#1
[eluser]Jaketoolson[/eluser]
I'm using $_GET for the majority of my forms and have had no problems with this using CI 2.0. In form_helpers and other places, you only check for $_POST and never for $_GET. I understand this is an obvious observation, but since you've enabled query_string and $_GET support, it would be nice if you could quickly enable this throughout all methods and functions.

for example, currently I can't use set_value() in any of my forms :
Code:
function set_value($field = '', $default = '')
    {
        if (FALSE === ($OBJ =& _get_validation_object()))
        {
            if ( ! isset($_POST[$field]))
            {
                return $default;
            }

            return form_prep($_POST[$field], $field);
        }

        return form_prep($OBJ->set_value($field, $default), $field);
    }

Also, the form helper functions are inconsistent. For example, form_dropdown() and form_hidden() functions do not allow me to pass an array of 'extra parameters' yet the other form helper functions do...

For now, I'll have to extend all functions where this occurs just thought it would be nice to consider updating.

#2
[eluser]c77m[/eluser]
In case it helps anybody else, here is my MY_form_helper.php that adds GET string functionality for set_value and set_select. (Sorry, I'm not using any others in my forms at this point, so I only modified these two.) Not complex, but save you a few mins...

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Form Value
*
* Grabs a value from the POST array for the specified field so you can
* re-populate an input field or textarea.  If Form Validation
* is active it retrieves the info from the validation class
*
* @access    public
* @param    string
* @return    mixed
*/
if ( ! function_exists('set_value'))
{
    function set_value($field = '', $default = '')
    {
        if (FALSE === ($OBJ =& _get_validation_object()))
        {
            if ( !isset($_POST[$field]) AND !isset($_GET[$field]))
            {
                return $default;
            }

            if (isset($_POST[$field]))
            {
                return form_prep($_POST[$field], $field);
            }
            
            return form_prep($_GET[$field], $field);
        }

        return form_prep($OBJ->set_value($field, $default), $field);
    }
}

// ------------------------------------------------------------------------

/**
* Set Select
*
* Let's you set the selected value of a <select> menu via data in the POST array.
* If Form Validation is active it retrieves the info from the validation class
*
* @access    public
* @param    string
* @param    string
* @param    bool
* @return    string
*/
if ( ! function_exists('set_select'))
{
    function set_select($field = '', $value = '', $default = FALSE)
    {
        $OBJ =& _get_validation_object();

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

            if (isset($_POST[$field]))
            {
                $field = $_POST[$field];
            } else {
                $field = $_GET[$field];
            }

            if (is_array($field))
            {
                if ( ! in_array($value, $field))
                {
                    return '';
                }
            }
            else
            {
                if (($field == '' OR $value == '') OR ($field != $value))
                {
                    return '';
                }
            }

            return ' selected="selected"';
        }

        return $OBJ->set_select($field, $value, $default);
    }
}



/* End of file MY_form_helper.php */
/* Location: ./application/helpers/MY_form_helper.php */


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.