Reputation: 1035
I have a form in Yii.
It have model Validation.
In that form I have to insert url in textfield.
eg:https://www.google.co.in
In database I kept fields as varchar.
Rules in model are
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('url', 'required'),
array('name, url', 'length', 'max' => 255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('name, url', 'safe', 'on' => 'search'),
);
}
How can I keep validation for this in Model?
Upvotes: 0
Views: 3113
Reputation: 89
Try This:-
return array(
array('yoururl', 'required'),
array('yoururl', 'url'),//for url validation
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('name, yoururl', 'safe', 'on' => 'search'),
):
Upvotes: 2
Reputation: 181
array('inputURL', 'url')
and if you want to add http in front if missing use
array('website', 'url',defaultScheme' => 'http')
Upvotes: 1
Reputation: 133390
You should use url validator
this way array('siteurl', 'url'),
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('url', 'required'),
array('name, url', 'length', 'max' => 255),
array('url', 'url'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('name, url', 'safe', 'on' => 'search'),
);
}
Upvotes: 0