Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
3acdd3ab
Commit
3acdd3ab
authored
Jun 20, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc improvement.
parent
0c14f47f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
input-validation.md
docs/guide/input-validation.md
+9
-6
No files found.
docs/guide/input-validation.md
View file @
3acdd3ab
...
...
@@ -105,7 +105,7 @@ declared in `rules()`.
Most validators have default error messages that will be added to the model being validated when its attributes
fail the validation. For example, the
[
[yii\validators\RequiredValidator|required
]
] validator will add
a message "Username cannot be blank." to a model when
its
`username`
attribute fails the rule using this validator.
a message "Username cannot be blank." to a model when
the
`username`
attribute fails the rule using this validator.
You can customize the error message of a rule by specifying the
`message`
property when declaring the rule,
like the following,
...
...
@@ -183,17 +183,20 @@ function whose return value determines whether to apply the rule or not. For exa
### Data Filtering <a name="data-filtering"></a>
User inputs often need to be filtered or preprocessed. For example, you may want to trim the spaces around the
`username`
input. You may use validation rules to achieve this goal. The following rule declaration shows
how to trim the spaces in the input by using the
[
trim
](
tutorial-core-validators.md#trim
)
core validator:
`username`
input. You may use validation rules to achieve this goal.
The following examples shows how to trim the spaces in the inputs and turn empty inputs into nulls by using
the
[
trim
](
tutorial-core-validators.md#trim
)
and
[
default
](
tutorial-core-validators.md#default
)
core validators:
```
php
[
[
'username'
,
'trim'
],
[[
'username'
,
'email'
],
'trim'
],
[[
'username'
,
'email'
],
'default'
],
]
```
You may also use the more general
[
filter
](
tutorial-core-validators.md#filter
)
validator
if your data filtering
need is more complex than space trimm
ing.
You may also use the more general
[
filter
](
tutorial-core-validators.md#filter
)
validator
to perform more complex
data filter
ing.
As you can see, these validation rules do not really validate the inputs. Instead, they will process the values
and save them back to the attributes being validated.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment