Welcome Guest, Not a member yet? Register   Sign In
$_GET and form inconsistancies -- suggestion to engineers.
#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 */


Messages In This Thread
$_GET and form inconsistancies -- suggestion to engineers. - by El Forum - 04-26-2011, 02:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB