亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Codeigniter - 表單驗證運行,但不會在 FALSE 上顯示錯誤

Codeigniter - 表單驗證運行,但不會在 FALSE 上顯示錯誤

PHP
人到中年有點甜 2023-03-04 14:35:13
我遇到了表單驗證的情況。對于如此簡單的事情,我似乎無法弄清楚我的問題出在哪里,并且我在網上搜索了很長時間。如果返回 FALSE ,我的表單留空時應該form_error為每個字段拋出錯誤form_validation。但是,沒有任何反應。當表單完全填寫時,它會很好地插入到數據庫中。我被困住了,我似乎無法弄清楚解決方案是什么。我的想法是代碼在某處有拼寫錯誤或表單設計不正確。這是我的控制器:function create_job()    {        // validate each form field        $this->form_validation->set_rules('repair_order', 'Repair Order', 'required');        $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');        $this->form_validation->set_rules('phone', 'Phone', 'required');        $this->form_validation->set_rules('vin', 'VIN', 'trim|required');        $this->form_validation->set_rules('year', 'Vehicle Year', 'trim|required|min_length[4]');        $this->form_validation->set_rules('make', 'Vehicle Make', 'required');        $this->form_validation->set_rules('model', 'Vehicle Model', 'required');        $this->form_validation->set_rules('start_date', 'Start Date', 'required');        $this->form_validation->set_rules('promise_date', 'Promise Date', 'required');        $this->form_validation->set_rules('body_hours', 'Body Labor Hours', 'required');        $this->form_validation->set_rules('paint_hours', 'Paint Labor Hours', 'required');        $this->form_validation->set_rules('body_tech', 'Body Technician', 'required');        $this->form_validation->set_rules('paint_tech', 'Paint Technician', 'required');                );                $this->db->insert('jobs', $data);                $this->session->set_flashdata("success", "New job has been successfully created.");                redirect('main');            }            else            {                redirect('jobs/new');            }    }我是 CodeIgniter 的新手,只是想學習。如果有人能看到問題出在哪里并能指導我找到答案,我將不勝感激。
查看完整描述

1 回答

?
12345678_0001

TA貢獻1802條經驗 獲得超5個贊

您的重定向不會傳遞 form_error 消息。您需要加載一個視圖(您的表單)才能調用 form_error 使用$this->load->view()


嘗試這個:


function create_job()

{

    // validate each form field

    $this->form_validation->set_rules('repair_order', 'Repair Order', 'required');

    $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');

    $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');

    $this->form_validation->set_rules('phone', 'Phone', 'required');

    $this->form_validation->set_rules('vin', 'VIN', 'trim|required');

    $this->form_validation->set_rules('year', 'Vehicle Year', 'trim|required|min_length[4]');

    $this->form_validation->set_rules('make', 'Vehicle Make', 'required');

    $this->form_validation->set_rules('model', 'Vehicle Model', 'required');

    $this->form_validation->set_rules('start_date', 'Start Date', 'required');

    $this->form_validation->set_rules('promise_date', 'Promise Date', 'required');

    $this->form_validation->set_rules('body_hours', 'Body Labor Hours', 'required');

    $this->form_validation->set_rules('paint_hours', 'Paint Labor Hours', 'required');

    $this->form_validation->set_rules('body_tech', 'Body Technician', 'required');

    $this->form_validation->set_rules('paint_tech', 'Paint Technician', 'required');


        if($this->form_validation->run())

        {

            $data = array(

            'repair_order'      => $this->input->post('repair_order'),

            'first_name'        => $this->input->post('first_name'),

            'last_name'         => $this->input->post('last_name'),

            'address'           => $this->input->post('address'),

            'city'              => $this->input->post('city'),

            'state'             => $this->input->post('state'),

            'zip_code'          => $this->input->post('zip_code'),

            'phone'             => $this->input->post('phone'),

            'vin'               => $this->input->post('vin'),

            'year'              => $this->input->post('year'),

            'make'              => $this->input->post('make'),

            'model'             => $this->input->post('model'),

            'start_date'        => $this->input->post('start_date'),

            'promise_date'      => $this->input->post('promise_date'),

            'body_hours'        => $this->input->post('body_hours'),

            'paint_hours'       => $this->input->post('paint_hours'),

            'insurance'         => $this->input->post('insurance'),

            'body_tech'         => $this->input->post('body_tech'),

            'paint_tech'        => $this->input->post('paint_tech')

            );

            $this->db->insert('jobs', $data);


            $this->session->set_flashdata("success", "New job has been successfully created.");

            redirect('main');

        }

        else

        {

            $this->load->view('yournewjobform');

        }

}


查看完整回答
反對 回復 2023-03-04
  • 1 回答
  • 0 關注
  • 110 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號