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

前端 未结 8 706
天涯浪人
天涯浪人 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:37

    I've found that where:

    1. there's more than one CI view-partials which make up the page and their controller methods perform validation
    2. one of the validations failed and produced an error since the last page-refresh, say with an incorrectly formatted or typed input field value

    it isn't enough to clear only the validation-rules array, you need to clear the validation-error array too.

    To this end, I've added a method to system/libraries/Form_Validation.php, as follows:

    public function clear_rules()
    {
        $this->_error_array = array();
        $this->_field_data = array();
        return $this;
    }
    

    Returning $this is important if you want to chain your form-validation methods.

    0 讨论(0)
  • 2020-12-23 21:37

    In newer version 3.X, to clear set_value , $_POST=array() and $this->_field_data = array(); in MY_Form_validation.php library. try

    Clear form data after success codeigniter using php not jquery

    0 讨论(0)
提交回复
热议问题