Welcome Guest, Not a member yet? Register   Sign In
Adding new validation
#2

(This post was last modified: 10-12-2021, 12:51 AM by Knutsford.)

(10-11-2021, 11:05 AM)Knutsford Wrote: How do I add a new form validation?


I have
PHP Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class MY_Form_validation extends CI_Form_validation {
      function __construct($config = array()){
   parent::__construct($config);
   $this->CI =& get_instance();
          $this->_config_rules = $config;
    }  
 
    function alpha_space($str) {    
 
        $this->CI->form_validation->set_message('alpha_space', 'The %s may only contain Alpha Characters and Spaces.');
        if (trim($value) !== "" & Is_a_Letter_or_Space($value)) { 
                return TRUE;
        } 
 else {
              return FALSE;
    }
    }
 
 function Is_a_Letter_or_Space($inputbox) {  

 $teststring = Trim($inputbox);
 if ($teststring == "") {
 return False; 

 } 

 $i = 0;
 while ($i <= strlen($teststring) - 1) {
 $c = strtolower(substr($teststring,$i,1)); 

 if ($c <> "a" & $c <> "b" & $c <> "c" & $c <> "d" & $c <> "e" & $c <> "f" & $c <> "g" & $c <> "h" & $c <> "i" & $c <> "j" & $c <> "k" & $c <> "l" & $c <> "m" & $c <> "n" & $c <> "o" & $c <> "p" & $c <> "q" & $c <> "r" & $c <> "s" & $c <> "t" & $c <> "u" & $c <> "v" & $c <> "w" & $c <> "x" & $c <> "y" & $c <> "z" & $c <> " ") { 
 return False;
 }
 $i = $i + 1;
 } 
 return True;
 }


Code:
But it is causing a Javascript error

There are the rules

'order-info-form' => array(
Code:
                                    array(
Code:
                                            'field' => 'order_first_name',
Code:
                                            'label' => 'First name',
Code:
                                            'rules' => 'trim|required|alpha_space'
Code:
                                        ),
Code:
                                    array(
Code:
                                            'field' => 'order_last_name',
Code:
                                            'label' => 'Last name',
Code:
                                            'rules' => 'trim|required|alpha_space'
Code:
                                        ),

etc


Thanks




It is Codeigniter 2  if that helps
Reply


Messages In This Thread
Adding new validation - by Knutsford - 10-11-2021, 11:05 AM
RE: Adding new validation - by Knutsford - 10-12-2021, 12:49 AM
RE: Adding new validation - by InsiteFX - 10-12-2021, 01:20 AM
RE: Adding new validation - by Knutsford - 10-12-2021, 01:51 AM
RE: Adding new validation - by includebeer - 10-12-2021, 03:31 PM
RE: Adding new validation - by Knutsford - 10-13-2021, 01:31 AM
RE: Adding new validation - by includebeer - 10-13-2021, 08:11 AM
RE: Adding new validation - by Knutsford - 10-14-2021, 01:12 AM
RE: Adding new validation - by includebeer - 10-14-2021, 06:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB