CodeIgniter - можно зацепить form_validation-> set_rules в функции обратного вызова? - PullRequest
0 голосов
/ 04 сентября 2018

Привет, у меня проблема с проверкой правильности через функцию обратного вызова. $ this-> form_validation-> set_message работает, но $ this-> form-> validation-> set_rules нет. TIA

<?php
if (!defined('BASEPATH')) {
  exit('No direct script access allowed');
}

class Users extends CI_Controller {
  public function validate_form() {

    $data = array('success' => false, 'messages' => array());

    $this->load->library('form_validation');
    $this->form_validation->set_rules('Employed', '', 'required|callback_is_employed');
    $this->form_validation->set_error_delimiters('<p class="text-danger">','<br />','</p>');

    if ($this->form_validation->run()) {
        $data['success'] = true;
    } else {
        foreach ($_POST as $key => $value) {
            $data['messages'][$key] = form_error($key);
        }
    }
    echo json_encode($data);
  }

  public function is_employed() {
    if($this->input->post('Employed')) {
        $this->form_validation->set_message('is_employed', 'data is checked');
        $this->form_validation->set_rules('EmployedNoB', 'EmployedNoB', 'trim|required');
        $this->form_validation->set_rules('EmployedCA', 'EmployedCA', 'trim|required');
        $this->form_validation->set_rules('EmployedCN', 'EmployedCN', 'trim|required');
        return false;
    }
  }
}
?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...