Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
CALLBACK VALIDATION - CUSTOM VALIDATION
  • Hello I am new in fuelphp. My prior framework is code igniter. Code igniter has very great documentation, so easily learning. I am moving to fuelphp because code igniter is not development again. But in fuel php I have one problem about callback validation. In code igniter is very easy to implement custom validation like the documentation
    class Form extends CI_Controller {
    public function index()
    {
    $this->load->helper(array('form', 'url'));
    $this->load->library('form_validation');
    $this->form_validation->set_rules('username', 'Username', 'callback_username_check');
    if ($this->form_validation->run() == FALSE)
    {
    $this->load->view('myform');
    }
    else
    {
    $this->load->view('formsuccess');
    }
    }

    public function username_check($str)
    {
    if ($str == 'test')
    {
    $this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
    return FALSE;
    }
    else
    {
    return TRUE;
    }
    }
    }
    ?>
    In fuelPHP, I have read documentation but still confuse. I am try this
    class MyRules
    {
    // note this is a static method
    public static function _validation_username_chek($strusername)
    {
    if ($strusername=="tes") {

    return 1;

    } else {
    return 2;
    }
    }
    }

    $val->add_callable('MyRules');
    $val->add('username', 'Your username', array(), array('trim'))->add_rule('username_chek');
    But get error InvalidArgumentException [ Error ]: Input for add_callable is not a valid object or class.
    Can anyone help me to solve this…please give me example like code igniter documentation above..
  • You get this error if:
    - you don't pass an object (which you don't)
    - the class you pass can not be found

    According to Fuel's naming rules, this class should be called Myrules (not MyRules), should be in a file called "myrules.php" (all lowercase), and in ./fuel/app/classes.

    It that the case?
  • Your class MyRules has no namespace ? Try $val->add_callable('\MyRules');
  • thanks Harro and Syntaxlb...

    i am not put myrules.php in the right place... when i move it to folder /fuel/app/classes.. problem solve...

    my plan fuelphp will be the next my project .. i am very exited if the documentation prepare more example like code igniter's user guide....clear and complete example... because i am also new in PHP language ... untill now i still working with desktop programming foxpro and java 

    i think if documentation like code igniter i am sure that this framework will be popular

    thank you very much..




  • @SyntaxIb.

    Classes in strings are always relative to global, so a leading backslash is not needed.

    As for documentation, the current documentation was setup as API documentation, for lack of alternatives, about three years ago. It's created in plain HTML, which is very difficult to maintain.

    Fuel version 2 will have complete new documentation, which will have a functional focus, with lots of howto's and examples, and will not be used for API documenation (we now use PHPdocumentor for that).
  • Ok thanks for this info Harro ;-)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion