我尝试对表单验证进行测试,但是当我在表单字段中输入一个好的条目时,它总是给我“无法连接”的消息。这是我的控制器脚本:
<?php
public function traitement(){
$this->load->library('form_validation');
$pseudo = $this->input->post('pseudo');
$mdp = $this->input->post('mdp');
$this->form_validation->set_rules('pseudo', '"Nom d\'utilisateur"', 'trim|required|min_length[5]|max_length[52]|alpha_dash|encode_php_tags|xss_clean');
$this->form_validation->set_rules('mdp', '"Mot de passe"', 'trim|required|min_length[5]|max_length[52]|alpha_dash|encode_php_tags|xss_clean');
if($this->form_validation->run())
{
// the form is verified
echo 'connected ';
}
else
{
// the form is invalide
echo 'unable to connect';
}
}
答案 0 :(得分:0)
尝试$this->form_validation->run() ==TRUE
<?php
public function traitement(){
$this->load->library('form_validation');
$pseudo = $this->input->post('pseudo');
$mdp = $this->input->post('mdp');
$this->form_validation->set_rules('pseudo', '"Nom d\'utilisateur"', 'trim|required|min_length[5]|max_length[52]|alpha_dash|encode_php_tags|xss_clean');
$this->form_validation->set_rules('mdp', '"Mot de passe"', 'trim|required|min_length[5]|max_length[52]|alpha_dash|encode_php_tags|xss_clean');
if($this->form_validation->run() ==TRUE)
{
// the form is verified
echo 'connected ';
}
else
{
// the form is invalide
echo 'unable to connect';
}
}
?>
答案 1 :(得分:0)
试试这个...
<?php
public function traitement(){
$this->load->library('form_validation');
$pseudo = $this->input->post('pseudo');
$mdp = $this->input->post('mdp');
$this->form_validation->set_rules('pseudo', '"Nom d\'utilisateur"', 'trim|required|min_length[5]|max_length[52]|alpha_dash|encode_php_tags|xss_clean');
$this->form_validation->set_rules('mdp', '"Mot de passe"', 'trim|required|min_length[5]|max_length[52]|alpha_dash|encode_php_tags|xss_clean');
if(!$this->form_validation->run())
{
// the form is Invalid
echo 'unable to connect ';
}
else
{
// the form is valid
echo 'connected';
}
}
?>
答案 2 :(得分:0)
我发现此规则(xss_clean)的问题,当我删除它,没有问题检测到!