这里是我的控制器代码:我有开发笨,但表单验证错误的项目中的其他conditon没有显示出任何错误
public function onlineordercheck()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('postcode', 'Postcode',
'required|trim|integer|max_length[4]',
array('integer' => 'We are sorry, currently we do not provide services in your area.',
'max_length[4]'=>'We are sorry, currently we do not provide services in your area.'));
$this->form_validation->set_error_delimiters("<div class='text-danger'>","</div>");
if($this->form_validation->run())
{
$postcode= $this->input->post('postcode');
$this->load->model('Common_m');
$check_code=$this->Common_m->check_pincode($postcode);
if($check_code)
{
//Credentials valid login user
$this->session->set_userdata('postcode',$check_code);
$this->load->view('template',array('page_title'=>'pageName','middle_view'=>'schedule_pickup'));
}
else
{
//authentication failed
$this->load->view('template',array('page_title'=>'pageName','middle_view'=>'online_order'));
$this->form_validation->set_message('postcode', 'Service for this postcode is not available.');
}
}
else
{
$this->load->view('template',array('page_title'=>'pageName','middle_view'=>'online_order'));
}
}
这是我的看法页:
<div class="container" style="margin:20px;">
<div class=" col-sm-12 row">
<div class="col-sm-12">
<div class="col-sm-12 thumbnail text-center">
<img alt="" class="img-responsive" src=`"<?php echo base_url(); ?>`images/imageName.jpg">
<div class="caption">
<?php echo form_open('COrders/onlineordercheck', [ 'class' => 'form-horizontal' ]); ?>
<div class="title">Postcode</div>
<?php echo form_input([ 'name' => 'postcode', 'placeholder' => 'Postcode' ]) ?>
<?php echo form_error('postcode'); ?>
<?php echo form_submit
([
'class' => 'btn btn-primary',
'type' => 'submit',
'value' => 'Check Times'
]) ?><?php echo form_close(); ?>
</div>
</div>
</div>
</div>
</div>
我有负载form_helper
并在构造函数中构造验证库。当check_pincode($pincode)
方法返回false
那个时候set_message
不工作...
什么会变成set_message
显示错误。