Welcome Guest, Not a member yet? Register   Sign In
Codeigniter form validation
#1

[eluser]Unknown[/eluser]
Hi guys, i'm new to codeigniter, and i am doing a project.
I am trying to use the built in validation tools to validate a form. However, the form does not want to validate, even with the proper input. Can anyone tell me what i am doing wrong?
I am using jquery mobile. will this casue my problem?
Below is my code

Controller (named 'mainController.php'):
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MainController extends CI_Controller {

public function index()
{
  $this->load->helper("form");
  $this->load->library("form_validation");
  
  $this->form_validation->set_rules("email", "Email Address", "required|valid_email");
  $this->form_validation->set_rules("password", "Password", "required");
  $this->form_validation->set_rules("institution", "Institution", "required");
  
  if ($this->form_validation->run() == false){
          $this->load->view("index");
  }
  else{
    $this->load->view("welcome_message");
  }

}
}
?>

View (named 'index.php'):
the removed lines of code are scripts for including jquery and jquery mobile libraries

Code:
<html lang="en">
  <head>
    <meta name="viewport" c initial-scale=1, maximum-scale=1">
<meta charset="utf-8">
<title>BCC Application - Login</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
[removed][removed]
[removed][removed]
  </head>
  <body>
   <div data-role="page" id="login">
  <div data-role="content">
    <h1>Application form</h1>
    <p>Please log in to view your application</p>
    <p><a href="">Don't Have an application? Click to create one</a></p>
    
    &lt;?php echo validation_errors(); ?&gt;
    &lt;?php echo form_open('form'); ?&gt;
      <label for="email">Email Address</label>
   &lt;input type="text" name="email"&gt;&lt;br>
  
   <label for="password">Password</label>
   &lt;input type="password" name="password"&gt;&lt;br>
  
   <label for="institution">Institution</label>
   <select name="institution">
       <option>Barbados Community College</option>
    <option>Samuel Jackson Prescod Polytechnic</option>
    <option>Eridston College</option>
   </select><br>
  
   &lt;input type="submit" name="submit" value="Submit"&gt;
    &lt;/form&gt;
    
  </div>&lt;!--End content--&gt;
  &lt;?php
    include("templates/footer.php");
  ?&gt;
   </div>&lt;!--End login page--&gt;
  &lt;/body&gt;
&lt;/html&gt;

Thanks in advance for any help
#2

[eluser]Unknown[/eluser]
I found the problem.
It has to do with my opening the form: &lt;?php echo form_open('form'); ?&gt; should have been &lt;?php echo form_open('mainController'); ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB