[eluser]ch5i[/eluser]
Here's what I use:
(thx for the inspiration, Moobies)
Seems to work quite well.
EDIT: Is in production now
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
// include native CI_Validation class file
include_once(BASEPATH.'libraries/Form_validation.php');
/**
* MY_Form_validation Class, extends CI_Form_validation
*
* @package CodeIgniter
* @subpackage Libraries
* @category Validation
*/
class MY_Form_validation extends CI_Form_validation {
/**
* MY_Form_validation::MY_Form_validation()
*
* Constructor
*
* @return void
*/
public function MY_Form_validation()
{
parent::CI_Form_validation();
log_message('debug', "MY_Form_validation Class Initialized");
}
// --------------------------------------------------------------------
/**
* MY_Form_validation::put_value()
*
* Set default value for validation fields
*
* @param string $field
* @param string $value
* @return void
*/
public function put_value($field = null, $value = '')
{
if (is_null($field)) {
return;
} else {
$this->_field_data[$field]['postdata'] = $value;
}
}
// --------------------------------------------------------------------
/**
* MY_Form_validation::get_value()
*
* Returns the value of a validation field
*
* @param string $field
* @return mixed
*/
public function get_value($field = null)
{
if ( is_null($field) || ( ! array_key_exists($field, $this->_field_data)) ) {
return FALSE;
} else {
return $this->_field_data[$field]['postdata'];
}
}
// --------------------------------------------------------------------
}
// END MY_Form_validation Class
This basically adds two methods to the form validation library, one to (pre-) set values and one to retrieve values.