Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Validation Issue allow dashes do not works
  • Hi,

    i validate a comment field, therfore i have following rules:

    $validation->add_field('message', 'Nachricht', 'required|trim|max_length[400]|htmlentities|valid_string[alpha,dashes,numeric,spaces,quotes,punctuation,newlines,commas,tabs,braces,brackets,utf8]|min_length[5]');
    I need to allow dashes, but i already done this and it still not working.
    Did i use something wrong?
  • I don't have a problem with it.

    $val = Validation::forge('test');
    $val->add_field('message', 'Nachricht', 'required|trim|max_length[400]|htmlentities|valid_string[alpha,dashes,numeric,spaces,quotes,punctuation,newlines,commas,tabs,braces,brackets,utf8]|min_length[5]');

    return $val->run(array('message' => 'x-x-x-x')) ? 'PASSED' : $val->show_errors();

    Returns 'PASSED', and does not give any validation errors.
  • This is my code and i got every time that the dashes not working:

    $validation = \Fuel\Core\Validation::forge();
    $validation->add_field('user_name', 'Name', 'required|trim|valid_string[utf8]|min_length[3]|max_length[70]');
    $validation->add_field('email', 'E-Mail Adresse', 'required|trim|valid_email');
    $validation->add_field('message', 'Nachricht', 'required|trim|max_length[400]|htmlentities|valid_string[alpha,dashes,numeric,spaces,quotes,punctuation,newlines,commas,tabs,braces,brackets,utf8]|min_length[5]');

    if( $validation->run( ) )
    {
    $articles = \Model_Comment::forge( $data );

    if( $articles->save() )
    {
    return \Fuel\Core\Response::redirect( 'comments/index/' . $article_id );
    }
    }
  • sry i allready solved it. it was my mistake. i did work in the wrong file.... thats why it didn´t work...
  • Unrelated to this problem, but never use the \Fuel\Core namespace.It breaks certain features of the framework. All core classes are available in the global namespace.

    I can not reproduce it. This is my test action:

        public function action_test()
        {
            $validation = Validation::forge();
            $validation->add_field('user_name', 'Name', 'required|trim|valid_string[utf8]|min_length[3]|max_length[70]');
            $validation->add_field('email', 'E-Mail Adresse', 'required|trim|valid_email');
            $validation->add_field('message', 'Nachricht', 'required|trim|max_length[400]|htmlentities|valid_string[alpha,dashes,numeric,spaces,quotes,punctuation,newlines,commas,tabs,braces,brackets,utf8]|min_length[5]');

            if( $validation->run())
            {
                var_dump('PASSED', $validation->validated());
            }
            else
            {
                var_dump('FAILED', $validation->show_errors(), $validation->validated());
            }
        }

    I created a dummy form to test it, and when I post it, i get
    string 'PASSED' (length=6)
    array (size=3)
    'user_name' =>
    string 'test' (length=4)
    'email' => string 'test@example.org' (length=16)
    'message' => string 'x-x-x-x-x-x' (length=11)
    Are you sure you're form actually posts (method="POST") and not gets by mistake? If it doesn't pass, what does show_errors() gives you?
  • HarroHarro
    Accepted Answer
    ah, ok.

Howdy, Stranger!

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

In this Discussion