Skip to content

Commit

Permalink
Merge pull request cakephp#2330 from cakephp/issue-2326
Browse files Browse the repository at this point in the history
Add quick example of using uploadedFile rule.
  • Loading branch information
antograssiot committed Jan 27, 2015
2 parents 218eb35 + 1823426 commit 01199d4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions en/core-libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,15 @@ not a particular rule should be applied::
]);

The above example will make the rule for 'picture' optional depending on whether
the value for ``show_profile_picture`` is empty.
the value for ``show_profile_picture`` is empty. You could also use the
``uploadedFile`` validation rule to create optional file upload inputs::

The same can be done for the ``allowEmpty()`` and ``notEmpty`` validation method.
Both take a callable function as the last argument, which determines whether or
$validator->add('picture', 'file', [
'rule' => ['uploadedFile', ['optional' => true]],
]);

The ``allowEmpty()`` and ``notEmpty()`` methods will also accept a callback
function as their last argument. If present, the callback determines whether or
not the rule should be applied. For example, a field can be sometimes allowed
to be empty::

Expand Down

0 comments on commit 01199d4

Please sign in to comment.