How do I call the trim function on a Kohana 3.2 validation object?

How can I call the trim function on a validation object in Kohana 3.2? I am using:

$post = Validation::factory($this->request->post());
$post->rule('Email', 'trim');

Upvotes: 3

Views: 1869

Answers (2)

matino
matino

Reputation: 17735

In addition to Darsstar reply - if you need recursive version of array_map, check out Arr::map function:

$post = Arr::map('trim', $this->request->post());

Upvotes: 2

Darsstar
Darsstar

Reputation: 1895

Validation objects are read only as of 3.2. Filter the input before creating the Validation object like so:

$post = array_map('trim', $this->request->post()); // $post[key] = expression; if it is for one specific value

$post = Validation::factory($post);

// set validation rules etc

Upvotes: 4

Related Questions