Yii Cmodel Rules validation get error message, yiicmodel_php tutorial

Source: Internet
Author: User
Tags yii

Yii Cmodel in the rules validation get error message, Yiicmodel


defined in model  Public function rules () {        return array(' name,email ', ' required '),                        Array(' Email ', ' unique ', ' message ' = ' {value} ' ERROR '),//{value} is the added data        );    } Use $modelnew MyModel () in the controller; // to instantiate a model class for a related table $model $_post // The attributes assignment is the data that is submitted (need to be verified), and the field is safe in rules $model->validate (); // The validation rule rules are automatically invoked here $model->geterrors (); // get error messages for all validation fields $model->geterrors (' Email '); // gets the error message for the current incoming field $model->geterror (' Email '); // ' Message message '


How Yii gets the wrong form information and saves it in a string

This with
Chtml::errorsummary ($model 1)
You can check the manual, and his return is a string.

Yii form error message in which file

Your question description is not very clear, I will give you the Yii form verification!
Yii form validation You can refer to the Sitecontroller actioncontact method of the blog in its demos:
Public Function Actioncontact ()
{
$model =new Contactform;
if (Isset ($_post[' contactform '))
{
$model->attributes=$_post[' contactform '];
if ($model->validate ())
{
$headers = "From: {$model->email}\r\nreply-to: {$model->email}";
Mail (Yii::app ()->params[' AdminEmail '), $model->subject, $model->body, $headers);
Yii::app ()->user->setflash (' Contact ', ' Thank "for contacting us. We'll respond to as soon as possible. ');
$this->refresh ();
}
}
$this->render (' Contact ', array (' model ' = $model));
}
I will not list the part of the model here, see its demo inside it!
This method is after the form is submitted
if (Isset ($_post[' contactform ')) determines whether the form submits the status of the

$model->attributes=$_post[' contactform '); Assign form data to the Model property

if ($model->validate ()) This step is to call the model inside the validation, if there is an error will return an error, so that the view will be reloaded, so that the view inside the error portion of the form will be wrong output!

Errorsummary ($model);?>

This part comes from the wrong output part of the view!

http://www.bkjia.com/PHPjc/863231.html www.bkjia.com true http://www.bkjia.com/PHPjc/863231.html techarticle Yii Cmodel Rules validation gets error message, Yiicmodel defines public function rules () {return array (' Name,email ', ' required ') in model , Array (' Email ', ' unique ', ' message ' ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.