Form validation stops working when I render pages using another controller

早过忘川 提交于 2019-12-02 06:06:48

Create a view called template.php in your views folder with the following code in it:

<?php

$this->load->view('fragments/header', $this->_ci_cached_vars); // pass $data vars
$this->load->view('fragments/navigation');
$this->load->view($view);
$this->load->view('fragments/navigation');
$this->load->view('fragments/footer');

Then use the below controller code:

public function index() {

    $this->form_validation->set_rules('sender_name', 'From', 'required');
    $this->form_validation->set_rules('sender_email', 'Email', 'required|valid_email');
    $this->form_validation->set_rules('subject', 'Subject', 'required');
    $this->form_validation->set_rules('message', 'Message', 'required');

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

        $data = array(
            'view' => 'contact/contact', 
            'title' => 'Contact Me');
        $this->load->view('template', $data);
    }

You don't need to create a library to do this as you can just create a template view which will load the appropriate views and the specified view and pass the data along to them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!