Helo,
So I have a little problem with form_validation in Codeigniter, here is the controller -
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Records extends CI_Controller {
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->helper('url');
$this->load->view('includes/header');
$this->load->view('products');
$this->load->view('includes/footer');
}
public function addRecord() {
$this->load->helper(array('form', 'url'));
$this->load->helper('url');
$query = $this->db->get_where('users', array('uname' => $this->session->userdata('username')));
foreach($query->result_array() as $row) {
$data = array(
'username' => $row['uname'],
'email' => $row['email'],
'name' => $row['name'],
'description' => $row['description'],
'picture' => $row['picture'],
'gender' => $row['gender'],
);
}
if($this->session->userdata('logged_in')) {
$this->load->view('includes/header');
$this->load->view('my_records', $data);
$this->load->view('includes/footer');
}
else {
redirect('/home', 'refresh');
}
}
public function postRecord() {
$this->lang->load('form_validation', 'latvian');
$this->load->library('form_validation');
$this->load->model('records');
$this->load->helper(array('form', 'url'));
if(!$this->session->userdata('logged_in')) redirect('/home', 'refresh');
$this->form_validation->set_rules('message', 'Ziņa', 'required|trim|min_length[5]|max_length[250]');
$query = $this->db->get_where('users', array('uname' => $this->session->userdata('username')));
foreach($query->result_array() as $row) {
$data = array(
'username' => $row['uname'],
'email' => $row['email'],
'name' => $row['name'],
'description' => $row['description'],
'picture' => $row['picture'],
'gender' => $row['gender'],
);
}
// If doesn't pass validation, redirect's back with errors.
if ($this->form_validation->run() == FALSE)
{
$this->load->helper('url');
$this->load->view('includes/header');
$this->load->view('my_records', $data);
$this->load->view('includes/footer');
}
// If everything is correct add's user.
else
{
$this->load->view('includes/header');
$this->load->view('my_records', $data);
$this->load->view('includes/footer');
}
}
} ?>
and view -
<div class="list-products">
<div>
<?php if(validation_errors()) { ?><div class="error-submit"><p><?php echo validation_errors(); ?></p></div><?php } ?>
<form class="fix-this form" method="post" action="/savieno/records/postRecord">
<div class="formfield">
<span class="profile">Your message:</span>
<textarea id="message" name="message" class="with-label" rows="10" cols="10" placeholder="your message."></textarea>
</div>
<div class="formfield">
<input type="submit" id="submit" name="postRecord" value="Pievienot" class="fix-this" />
</div>
</form>
</div>
At start, it gave me error, that can’t find functio set_message(), but I added form_validation before form helper, and now it works, but again there is problem, cause it doesn’t display form error codes. It just ain’t displaying it at all, I have set error message for it, and it should work, but it isn’t. What could be the problem?