My controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class VerifyAppointment extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('appointment_model','',TRUE);
}
function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('rdatetimepicker', 'Appointment date', 'trim|required|xss_clean');
if($this->form_validation->run() == FALSE)
{
$this->load->view("pages/appointment");
}
else
{
$this->appointment_model->insert();
$data['posts'] = "hih";
$this->load->view('pages/appointment',$data);
}
}
}
My view:
<?php
echo $posts;
?>
You getting error because view dont get $posts when validation condition is false for that you initialize $data['posts']=""; in the start or in every if condition as per your coding style
function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('rdatetimepicker', 'Appointment date', 'trim|required|xss_clean');
if($this->form_validation->run() == FALSE)
{
$data['posts']=""; //declare posts here
$this->load->view('pages/appointment',$data);
}
else
{
$this->appointment_model->insert();
$data['posts'] = "hih";
$this->load->view('pages/appointment',$data);
}
}
or you can check array before in view, like this; if you don't want to change your controller
<?php
if(isset($posts))
echo $posts;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With