Bug Report #2715

Access to some fields into callback

Added by Valeriy Viktorovskiy over 4 years ago. Updated over 4 years ago.

Status:ClosedStart date:03/16/2010
Priority:NormalDue date:
Assignee:Woody Gilk% Done:

0%

Category:Core
Target version:v3.0.4
Resolution:invalid Points:

Description

It's impossible to get access to ome fields into callback method.

Example:

$post = Validate::factory($_POST)
            ->callback('birthday',
                array('Model_Member', 'checkBirthday'));

public static function checkBirthday(Validate $post)
{
    print_r($post['birthday_m']);
}


I got "ErrorException [ Notice ]: Undefined property: Validate::$birthday_m".

Of course I can check fields using $_POST['birthday_m] but this way is not good.

PS: there was such feature in Kohana_pre3.

History

#1 Updated by Woody Gilk over 4 years ago

  • Status changed from New to Closed
  • Assignee set to Woody Gilk
  • Resolution set to invalid

Actually you want:

public function check_birthday(Validate $post, $input)
{
    echo Kohana::debug($post[$input]);
}

#2 Updated by Valeriy Viktorovskiy over 4 years ago

  • Status changed from Closed to Feedback

Your example doesn't work for Model. Please review snippet bellow.

$_POST =array('birthday_m' => 12, 'birthday_d' => 16, 'birthday_y'=>1950);

class Controller_Register extends Controller_Website {
    public function action_index($invite_code = null)
    {
        $post = Validate::factory($_POST)
                    ->callback('birthday_d', 'Model_Member::checkBirthday');

        if ($post->check()) {
          // all ok
        }
   }
}

class Model_Member extends Model {
    public static function checkBirthday(Validate $post, $input)
    {
        print_r($post['birthday_m']);
    }
}

#3 Updated by Isaiah DeRose-Wilson over 4 years ago

Valery, that's because birthday_m isn't an expected field so it will be removed. You need to add a filter/label/rule/callback for brithday_m if you want to be able to use it in your validation. This would do work (and you want the not empty rule anyway!):


$_POST =array('birthday_m' => 12, 'birthday_d' => 16, 'birthday_y'=>1950);

class Controller_Register extends Controller_Website {
    public function action_index($invite_code = null)
    {
        $post = Validate::factory($_POST)
                    ->rule('birthday_m', 'not_empty')
                    ->callback('birthday_d', 'Model_Member::checkBirthday');

        if ($post->check()) {
          // all ok
        }
   }
}

class Model_Member extends Model {
    public static function checkBirthday(Validate $post, $input)
    {
        print_r($post['birthday_m']);
    }
}

#4 Updated by Valeriy Viktorovskiy over 4 years ago

Isaiah DeRose-Wilson wrote:

...because birthday_m isn't an expected field so it will be removed.
[...]

Isaiah, thanks for explanation. I didn't expect such validate behavior.

#5 Updated by Lorenzo Pisani over 4 years ago

oops sorry o_o can't remove my own update >_>

#6 Updated by Isaiah DeRose-Wilson over 4 years ago

  • Status changed from Feedback to Closed

Also available in: Atom PDF