这里我想显示不同字段的验证消息
$this->form_validation->set_rules('email','Email','trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run('email') == FALSE)
{
print_r('Enter email');
}
if ($this->form_validation->run('password') == FALSE)
{
print_r('Enter password ');
}
如果我提供密码并将电子邮件字段留空,则这两条消息都显示在rest api
中任何人都可以帮助我
答案 0 :(得分:3)
对于你的情况,我认为这将工作得很好
$this->form_validation->set_rules('email','Email','trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->run();
if (form_error('email'))
{
echo 'Enter email';
exit;
}
if (form_error('password'))
{
echo 'Enter password';
exit;
}
答案 1 :(得分:0)
基于你的要求点
如果我提供密码并将电子邮件字段留空,则两条消息都是 显示在休息api
只需添加输入中所需的属性。
<form action="https://stackoverflow.com/login" method="post" accept-charset="utf-8">
<p>
<input class="email_input" type="email" name="email" value="" placeholder="yourmail@gmail.com" required>
</p>
<p>
<input class="password_input" type="password" name="password" value="" placeholder="Your password" required>
</p>
<p>
<input class="enter-button" type="submit" name="btnSubmit" value="ENTER">
</p>
</form>
答案 2 :(得分:0)
if($this->form_validation->run()==FALSE){
$errors = $this->form_validation->error_array();
echo json_encode($errors);
}
上面的代码也可以正常工作,它还在rest server codeigniter中显示正确的错误消息