[eluser]learning_php[/eluser]
Hi,
I have been trying to mt form validation error to display in it own div tag but when the form in reloaded the error is underneath the input box. I added a basic stylesheet and none of that is on the reloaded page either.
Any help would be most appreciated
Controller
Code:
<?php
class test extends Controller
{
function test()
{
parent::Controller();
}
function index()
{
$data['page_title'] = "Add Contact";
$this->load->view('test_view', $data);
}
function testadd()
{
$data['page_title'] = "Add Contact";
$this->form_validation->set_rules('CompanyName', 'CompanyName','required|xss_clean');
if ($this->form_validation->run() == false) {
$this->load->view('test_view',$data);
} else {
$this->db->insert('contacts', $_POST);
redirect('contacts', 'contacts');
}
}
}
View
Code:
<html>
<head>
<title><?= $page_title ?></title>
<link rel="stylesheet" type="text/css" href="./stylesheet.css" />
</head>
<body>
<div>
<ul>
<li><?= anchor('', 'Homepage'); ?></li>
</ul>
</div>
<?= form_open('test/testadd') ?>
<div id="contacts_form">
<div id="Contacts_companyName">
Company Name: <input type="text" name="CompanyName" id="CompanyName" AUTOCOMPLETE = "off"
value="<?php echo set_value('CompanyName'); ?>" />
</div>
<div id="Contacts_companyName_error"><?php echo form_error('CompanyName'); ?></div>
<input type="submit" value="Add Contact" />
<?= form_close() ?>
</div>
</body>
</html>
Model
Code:
php
class contacts_model extends Model
{
function contacts_model()
{
parent::model();
}
function getData()
{
$query = $this->db->get('contacts');
if ($query->num_rows() < 0) {
//show_error('databse is empty')
} else {
return $query->result();
}
}
}