Welcome Guest, Not a member yet? Register   Sign In
Form Validation Individual Field Validation
#1

I think it would be a really good idea if you guys could add individual field validation to the form validation class.  This would make it extremely easy to use the class to validate forms through AJAX.  For example, when a user types in a username in a registration form and they focus away from that field, you could check for whether or not that name is in use with a function that individually validates form fields.

My idea for something like this would look something like this:


PHP Code:
<?php

class Register extends CI_Controller {

     public function index(){

         //the register form

   }

   public function checkfield($field){

      $this->load->library('form_validation');

      if(!$this->form_validation->check_field('group'$field)){

         echo show_error($field);

      }




Then the ajax call would use the URL of something like example.com/register/checkfield/username and the succeeding JS would look something like this:


PHP Code:
if(usernameResponse != ''){
 
     alert
("That username is already in use!");



What are your guys' thoughts on this?
Reply


Messages In This Thread
Form Validation Individual Field Validation - by ShoeLace1291 - 03-31-2016, 02:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB