Reputation: 575
hi i am trying to make a simple validation form but fore some reason its not working i tried to fallow the codeigniter user guide but it dose not work for me fore some reason i am only a beginner.can someone have a look at my code and help me out tnx for you help. all i get is an error message page not found and the form itself dose not validate. when i clik the submit button it goes to this url HTTP://localhost/Surva/index.php/info/validation
controller
<?php
class Info extends CI_Controller{
public function index(){
$this->load->view('info_view');
$data ['name'] = $this->input->post('name');
$data ['second_name'] = $this->input->post('second_name');
$data ['phone'] = $this->input->post('phone');
$data ['email'] = $this->input->post('email');
if($this->input->post('submit')){
$this->form_validation->set_rules('name', 'Name', 'required|alpha|xss_clean');
$this->form_validation->set_rules('second_name', 'Second Name', 'required|alpha|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if ($this->form_validation->run()){
$this->info_model->add_record($data);
}
}
$this->load->view('survay_view');
}
}
?>
view
<html>
<head>
</head>
<body>
<?php
echo validation_errors();
echo form_open('info/validation'); ?>
<ul id="info">
<li><label for='name'>Name:</lable><?php echo form_input('name')?></li>
<li><label for='second_name'>Second Name:</lable> <?php echo form_input('second_name');?> </li>
<li><label fro='phpne'>Phone:</lable> <?php echo form_input('phone');?></li>
<li><label for='email'>Email:</lable><?php echo form_input('email');?></li>
<li><?php echo form_submit('submit', 'Start survay!!' );?></li>
</ul>
<?php echo form_close();?>
</body>
</html>
model
<?php
class Info_model extends CI_Model {
function get_records()
{
$query = $this->db->get('credentials');
return $query->result();
}
function add_record($data)
{
$this->db->insert('credentials', $data);
return;
}
}
?>
Upvotes: 0
Views: 112
Reputation: 30488
load the form_validation library in your controller, you forgot to load it.
public function index(){
$this->load->view('info_view');
$this->load->library('form_validation'); // load library.
...............
}
change
echo form_open('info/validation');
to
echo form_open('info/');
Upvotes: 0
Reputation: 2236
echo form_open('info/validation');
Your form asks to go into the controller called "Info", and a function called "validation".
Your controller does not have that function.
Try changing it to:
echo form_open('info');
since you are doing your validation in your index function.
Upvotes: 3