Codeigniter Form Validation - how to unset form values after success?

前端 未结 8 746
天涯浪人
天涯浪人 2020-12-23 20:36

I realise this request goes against the example provided in the CI documentation (which advises a separate \'success\' page view), but I would like to reutilise a given form

8条回答
  •  甜味超标
    2020-12-23 21:30

    The answer from d5avard is wrong, the CI form validation should have the rules array parsed to it: If you don't do this you can use form validation with posted data, but not with over-ride data.

    save this file as Libraries/MY_Form_validation.php

        /**
         * Class MY_Form_validation
         * @description extension of the CI_Form_validation
         * @property CI_DB_query_builder db database driver
         * @property CI_Benchmark benchmark
         * @property CI_Input input
         * @property CI_Output output
         */
        class MY_Form_validation extends CI_Form_validation
        {
            /**
             * MY_Form_validation constructor.
             * @param array $rules
             */
            function __construct($rules = array())
            {
                parent::__construct($rules);
                $this->_error_prefix        = '

    '; $this->_error_suffix = '

    '; } /** * Resets the form validation class for multiple runs. * @param array $rules */ public function initialise($rules = array()) { if (count($rules) == 0 ) { require (APPPATH.'config'.DIRECTORY_SEPARATOR.'form_validation.php'); $this->_config_rules = $config; } else { $this->_config_rules = $rules; } $this->_field_data = array(); $this->_error_array = array(); $this->_error_messages = array(); $this->_error_prefix = '

    '; $this->_error_suffix = '

    '; $this->error_string = ''; } }

提交回复
热议问题