Welcome Guest, Not a member yet? Register   Sign In
Extending Form_validation
#1

[eluser]RaGe10940[/eluser]
Hello,

I am trying to create my own validation rules however the rules that I am creating are being violated and no message is showing on the screen. Can some one help?

My extended library :

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

class MY_Form_Validation extends CI_Form_Validation
{
    function __construct()
    {
        parent::CI_Form_Validation();
    }

public function alpha_dash_space($str)
    {
        if (!preg_match("/^([-a-z0-9_ ])+$/i", $str))
        {
            $this -> form_validation -> set_message('alpha_dash_space', 'The %s field can only contain letters, spaces, and underscores allowed');
            return FALSE;
        }
    }


the rule sets in my config file called form_validation.php

Quote:'c_scholarshipmaintance/addnewscholarship' => array(
array(
'field' => 'scholname',
'label' => 'Scholarship Name',
'rules' => 'required|alpha_dash_space|max_length[150]'
),

Code:
echo form_input('scholname', set_value('scholname'), 'placeholder="Scholarship Name", autocomplete="off"');

and this is how I call it :

Code:
if ($this -> form_validation -> run('c_scholarshipmaintance/addnewscholarship'))// If no validation errors
        {
                //.........
        }

any help would be helpful
#2

[eluser]RaGe10940[/eluser]
Well... been working on this since about 7:00 AM and its not 5:20 PM -_-

fixed it :

Code:
class MY_Form_Validation extends CI_Form_Validation
{
    function __construct($config = array())
    {
        parent::__construct($config);
    }

had to load the config. Thanks for looking at least Smile
#3

[eluser]RaGe10940[/eluser]
Spoke to early...

So now, if I enter a good value like "cheese" for this rule :

Code:
public function is_sentence($str)
    {
        if (!preg_match("/^[a-zA-Z0-9-?._ -]+$/", $str))// Alpha, Int, Basic Punctuation, Hyphens, Underscores, Spaces
        {
            $this -> set_message('is_sentence', 'The %s field can only contain letters, digits, spaces, dashes and periods.');
            return FALSE;
        }
    }

then that indeed will return TRUE since it is a good value.

Well if that does happen the set_value('') does not echo out the value.

it only shows the value if FALSE is returned





Theme © iAndrew 2016 - Forum software by © MyBB