【问题标题】:Form_validation run false in codeigniterForm_validation 在 codeigniter 中运行为 false
【发布时间】:2015-03-10 12:22:58
【问题描述】:
"","style" => "height:450px;width:350px;margin-left:10px;background-color:white;"));?> 编辑属性 "> 说明:">
部门 >英语系 >数学系 >菲律宾部 >科学部 >社会学系 >MAPEH部门 >电脑部 >家政部 >价值观部
生命年数:">
费用:">
军官:">
数量:">
"btn btn-默认"));?>
public function edit_prop(){
        $this->form_validation->set_rules('description','Description','required');
        $this->form_validation->set_rules('quantity','Quantity','required');
        $this->form_validation->set_rules('lifeyears','Life Years','required');
        $this->form_validation->set_rules('cost','Cost','required');
        $this->form_validation->set_rules('accountable_officer','Accountable Officer','required');

        if($this->form_validation->run() == false){
            if($this->properties->update_prop() == true){
                $this->session->set_flashdata('updated', 'Updated Successfully!');
                redirect('properties_controller/view_properties');
            }
        }
        else{
            $data = array(
                    'id' => $this->input->post('id'),
                    'description' => $this->input->post('description'),
                    'accountable' => $this->input->post('accountable'),
                    'lifeyears' => $this->input->post('lifeyears'),
                    'cost' => $this->input->post('cost'),
                    'accountable_officer' => $this->input->post('accountable_officer'),
                    'quantity' => $this->input->post('quantity')
                );              
                $data['design'] = 'update_property';
                $data['title'] = 'Properties Corner!';
                $this->load->view('template_dashboard',$data);
       }

【问题讨论】:

  • 那么你的问题是什么?..
  • 把你的代码也整理一下,你有什么问题?

标签: php codeigniter


【解决方案1】:

在我认为您正在尝试做的事情类似于下面的代码之后,无法弄清楚您是什么。

建议下次先考虑您的问题。

仅作为示例

还要检查您是否已设置路线并在表单操作中使用

$routes['controller_name'] = "controller_name/index";
$routes['controller_name/add'] = "controller_name/add";
$routes['controller_name/edit/(:any)'] = "controller_name/edit/$1";

阅读用户指南。 http://localhost/project/something/edit/1 $this->uri->segment(what_your_id_is_in_url);

查看表单

action="<?php echo base_url('controller_name/edit' .'/'. $this->uri->segment(3));?>"

示例:

<?php

class Controller_name extends CI_Controller {

public function index() {

  if ($this->uri->segment(3) == TRUE) {
    $this->edit_prop();
  } else {
    $this->add_prop();
  }
}

public function add_prop() { 
}

public function edit_prop(){

$this->load->library('form_validation');

$data['design'] = 'update_property';
$data['title'] = 'Properties Corner!';

$this->form_validation->set_rules('description','Description','required');
$this->form_validation->set_rules('quantity','Quantity','required');
$this->form_validation->set_rules('lifeyears','Life Years','required');
$this->form_validation->set_rules('cost','Cost','required');
$this->form_validation->set_rules('accountable_officer','Accountable Officer','required');

if($this->form_validation->run() == false){

$this->load->view('template_dashboard', $data);

} else {

$this->load->model('model_name');

$id = $this->uri->segment(3); // Read User Guide. http://localhost/project/something/edit/1 $this->uri->segment(what_your_id_is_in_url);

$this->model_name->edit($id);

$this->session->set_flashdata('updated', 'Updated Successfully!');
redirect('properties_controller/view_properties');

}

}

型号

class Model_name extends CI_Model {

public function edit($id) {
    $data = array(
        'id' => $this->input->post('id'),
        'description' => $this->input->post('description'),
        'accountable' => $this->input->post('accountable'),
        'lifeyears' => $this->input->post('lifeyears'),
        'cost' => $this->input->post('cost'),
        'accountable_officer' => $this->input->post('accountable_officer'),
        'quantity' => $this->input->post('quantity')
    );    

    $this->db->where('id', $id);
    $this->db->update('table_name', $data);      

}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    相关资源
    最近更新 更多