Welcome Guest, Not a member yet? Register   Sign In
Form Validation validating default value
#2

[eluser]cmark[/eluser]
I solved it in this way:

Code:
<?

if (!defined('BASEPATH')) exit('No direct script access allowed');



class MY_Form_validation extends CI_Form_validation

{

    function MY_Form_validation($config = array())

    {

        parent::CI_Form_validation($config);

    }



    function run($group = '')

    {

        foreach ($this->_field_data as $field => $row)

        {

            // Fetch the data from the corresponding $_POST array and cache it in the _field_data array.

            // Depending on whether the field name is an array or a string will determine where we get it from.



            if ($row['is_array'] == TRUE)

            {

                $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']);

            }

            else

            {

                if (isset($_POST[$field]) AND $_POST[$field] != "")

                {

                    $this->_field_data[$field]['postdata'] = $_POST[$field];

                }

            }



            if ($row['label'] == $this->_field_data[$field]['postdata'] )

            {

                $message = 'Por favor, completa el '. $row['label'];



                // Save the error message

                $this->_field_data[$row['field']]['error'] = $message;



                if ( ! isset($this->_error_array[$row['field']]))

                {

                    $this->_error_array[$row['field']] = $message;

                }

            }



        }



        return parent::run($group);

    }

}



?>

Maybe exists another way to validate the Label without a callback; but really i don't know. Thanks,

Marco


Messages In This Thread
Form Validation validating default value - by El Forum - 08-13-2009, 04:32 PM
Form Validation validating default value - by El Forum - 08-13-2009, 05:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB