我正在使用codeigniter中的from,其中程序控制正在转移提交函数,我可以通过添加die函数来测试它。尽管set_rules()成功检查了条目,但控件未传递给if($ this-> form_validation-> run())此函数。它已经退出并运行die-2,我一直在测试程序流程。
以下是我的控制器代码
function addPost(){
$this->load->library('form_validation')
if($this->admin_lib->checkMembers()){
if($this->input->post('submit')){
//validate the form
$this->form_validation->set_rules('country','Country','required');
$this->form_validation->set_rules('city','City','required');
$this->form_validation->set_rules('area','Area','required');
$this->form_validation->set_rules('street','Street','required');
$this->form_validation->set_rules('house_no','House number','required|numeric');
if($this->form_validation->run()){
//add to database
die("dead-1");
if($this->members_model->addPost())
{
echo "Successfully made one entry will be validated";
}
else{
echo "Error uploading the datas into database Please contact us about the problem";
}
}
die("Dead -2");
}
$data['content']=$this->load->view('members/addPost','',true);
$this->load->view('members/home',$data);
}
else{
echo "you dont have preveledge to access this page ,<br/> LOgin link rakhnu paryo ";
}
}
答案 0 :(得分:0)
您的代码将始终调用die(&#34; Dead -2&#34;),因为它不是Else块的一部分。它直接位于您的If语句下方,这意味着,无论您的表单验证发生什么,它都将永远消亡。
考虑将您的代码更改为以下
if($this->form_validation->run())
{
//add to database
die("dead-1");
if($this->members_model->addPost())
{
echo "Successfully made one entry will be validated";
}
else
{
echo "Error uploading the datas into database Please contact us about the problem";
}
}
else
{
die("Dead -2");
}