I-AM-OBODO Posted March 26, 2012 Share Posted March 26, 2012 Hi, i don't really know why my form isn't working, even when i click on empty, its still not validating. Here's my code: Controller <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Services extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('services_model'); } public function view($page = 'easylife') { if ( ! file_exists('application/views/services/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); } $data['title'] = ucfirst($page); // Capitalize the first letter $this->load->view('templates/header', $data); $this->load->view('services/'.$page, $data); $this->load->view('templates/footer', $data); } public function advisory() { $this->load->helper('form'); $this->load->library('form_validation'); //$data['title'] = 'Create a news item'; $this->form_validation->set_rules('title', 'Title', 'required'); $this->form_validation->set_rules('sname', 'Surname', 'required'); $this->form_validation->set_rules('fname', 'First Name', 'required'); $this->form_validation->set_rules('email', 'Email', 'required'); $this->form_validation->set_rules('state', 'State', 'required'); $this->form_validation->set_rules('tel', 'telephone', 'required'); $this->form_validation->set_rules('msg', 'Message', 'required'); if ($this->form_validation->run() === FALSE) { $this->load->view('templates/header', $data); $this->load->view('services/'.$page, $data); $this->load->view('templates/footer', $data); } else { $this->news_model->set_news(); $this->load->view('services/success'); } } } Model <?php class Services_model extends CI_Model { public function __construct() { $this->load->database(); } function insert_entry() { $data = array( 'title' => $title, 'sname' => $name, 'fname' => $name, 'email' => $name, 'state' => $name, 'tel' => $name, 'msg' => $name, 'date' => $date ); $this->db->insert('advisory', $data); } } View <?php echo validation_errors(); ?> <?php echo form_open('services/advisory'); ?> <table width="80%" border="0" cellspacing="2" cellpadding="0"> <tr> <td align="right"> Title:</td> <td><select name="title" id="title"> <option value="mr">Mr</option> <option value="mrs">Mrs</option> <option value="ms">Ms</option> </select></td> </tr> <tr> <td align="right">Surname:</td> <td><input name="sname" type="text" id="sname" /></td> </tr> <tr> <td align="right">First Name:</td> <td><input name="fname" type="text" id="fname" /></td> </tr> <tr> <td align="right">Email:</td> <td><input name="email" type="text" id="email" /></td> </tr> <tr> <td align="right">State:</td> <td><input name="state" type="text" id="state" /></td> </tr> <tr> <td align="right">Telephone</td> <td><input name="tel" type="text" id="tel" /></td> </tr> <tr> <td align="right">Topic:</td> <td><select name="topic" id="topic"> <option value="0" selected="selected">Select Topic</option> <option value="1">PAYE</option> <option value="2">Capital Restructuring</option> </select></td> </tr> <tr> <td rowspan="2"> </td> <td><textarea name="msg" id="msg"></textarea></td> </tr> <tr> <td><input name="date" type="hidden" id="date" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </form> thanks Link to comment https://forums.phpfreaks.com/topic/259732-form-not-working/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.