After following the CodeIgniter tutorial for a form (https://www.codeigniter.com/userguide2/libraries/form_validation.html), I can't for the life in me get it to work.
All I seem to be getting is: Fatal error: Call to undefined function validation_errors() in /Applications/XAMPP/xamppfiles/htdocs/test_f/application/views/pages/contact_us.php on line 1
I'm using the latest version of CodeIgnitor (2.1.4)
Controller
<?php
class Form extends CI_Controller {
public function index() {
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if ($this->form_validation->run() == FALSE) {
$this->load->view('pages/contact_us');
} else {
$this->load->view('pages/formsuccess');
}
}
}
?>
View
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
Routes
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
Looks like the problem is with your routes. It appears you are routing everything to a controller called pages
.
If you remove the (:any)
route, then hit your form controller by going to:
index.php/form
or
add the following route before (:any)
$route['form'] = "form";
Then try again.