function form_submit (){
$this->load->library('form_validation');
$this->form_validation->set_rules('cname', 'Company Name', 'required');
$this->form_validation->set_rules('cpname', 'Contact Person Name', 'required');
$this->form_validation->set_rules('add1', 'Address Line 1 ', 'required');
if($this->form_validation->run() == TRUE) {
echo 'sucess';
}
else {
echo validation_errors();
}
}
这是我的表格
<form id="form_sub" action="controller/form_submit">
<div class="row">
<div class="col-sm-6">
<label>Company Name <span>*</span></label>
<input name="cname" type="text" value="" maxlength="100" />
<div class="clear"></div>
</div>
<div class="col-sm-6">
<label>Contact Person <span>*</span></label>
<input name="cpname" type="text" value="" maxlength="100" />
<div class="clear"></div>
</div>
<div class="col-sm-6">
<label>Address Line 1 <span>*</span></label>
<input name="add1" type="text" value="" maxlength="100" />
<div class="clear"></div>
</div>
<input type="submit" value="submit" />
</div>
</form>
所有时间$ this-&gt; form_validation-&gt; run()都返回false。我在这里缺少什么,即使我给出正确的值并提交表格也给出错误
答案 0 :(得分:2)
您错过了表单标记中的method
属性。它应该是
<form id="form_sub" action="<?php echo site_url('controller/form_submit');?>" method="POST">