title: PHP Codeigniter form submit using JQuery
body: <p>I am new to PHP Codeigniter framework. I am designing a page in which I am using a link. On clicking the link it is calling a jquery function, which submits form through jquery. I have used codeigniter form validation methods for server side validation and for the timebeing I have disabled the client side validation.</p>
  
  <p>The problem is that in this process when the form is submitted through jquery, the codeigniter form validation method is not working.</p>
  
  <p>But if I am using a submit button to submit the form then the codeigniter form validation method works perfectly.</p>
  
  <p>Please advise me what to do if I need to submit the form through jquery and use the codeigniter form validation method.</p>
  
  <p>Please find the code below:</p>
  
  <p>Login Form:</p>
  
  <pre><code>&lt;?php echo validation_errors(); ?&gt;
  &lt;form name="login-form" id="login-form" method="post" action="&lt;?php echo base_url();?&gt;index.php/login/login_form" &gt;
      &lt;H2&gt;Login&lt;/H2&gt;
      &lt;div id="login-box-name"&gt;
          Email:
      &lt;/div&gt;
      &lt;div id="login-box-field"&gt;
          &lt;input name="user-name" id="user-name" class="form-login" title="Please Enter Correct User Name" value="" size="30" maxlength="2048" /&gt;
      &lt;/div&gt;
      &lt;div id="login-box-name"&gt;
          Password:
      &lt;/div&gt;
      &lt;div id="login-box-field"&gt;
          &lt;input name="password" id="password" type="password" class="form-login" title="Please Enter Correct Password" value="" size="30" maxlength="2048" /&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;span class="login-box-options"&gt;
          &lt;input type="checkbox" name="1" value="1" title="Want this computer to remember you!!"&gt; Remember Me &lt;a href="#" id="login-div-change"&gt;Forgot password?&lt;/a&gt;
      &lt;/span&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;a href="" id="login-submit"&gt;
          &lt;img src="&lt;?php echo base_url();?&gt;assets/images/login-btn.png" width="110" height="40" style="margin-left:90px;" /&gt;
      &lt;/a&gt;
      &lt;input type="submit" name="submit" id="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p>jquery function to submit the form on clicking the "link":</p>
  
  <pre>
  
      $("#login-submit").click(function()
      {
      $('#login-form').submit();
      return false;
      });
  
  </pre>
  
  <p>Controller function:</p>
  
  <pre>
  
      public function login_form()
      {
  
          $this->load->helper(array('form', 'url'));
          $this->load->library('form_validation');
          $data['title'] = 'Log In';
  
          $data['errorMessage'] = '';
          $this->form_validation->set_rules('user-name', 'Email', 'required');
          $this->form_validation->set_rules('password', 'Password', 'required');
  
          if ($this->form_validation->run() == FALSE)
          {
          $this->load->view('templates/header', $data);
          $this->load->view('login', $data);
          $this->load->view('templates/footer');
          }
  
          else
          {
          $this->load->view('templates/header', $data);
          $this->load->view('templates/menu');
          $this->load->view('index', $data);
          $this->load->view('templates/footer');
          }
  
      }
  
  </pre>
  
  <p>Here if I click on the "Submit button of the form, then the codeigniter validation works for user-name and password fields. But if I click the link with id="login-submit", then it calls the jquery function and the form get submitted. But the codeigniter validation does not work for user-name and password fields this time.</p>
  
  <p>I need to submit the form through the link and the codeigniter validation function should work for this.</p>
  
  <p>Thanks in Advance.....</p>