注册时不用提交就验证用户名、邮箱等是否已将存在,用Ajax实现
首先,先在Form表中开启Ajax
...
<?php $form = ActiveForm::begin(['enableAjaxValidation' => true]); ?>
...
其次,再_对应的_Controller加入一段Ajax验证的代码
...
if ($model->load(Yii::$app->request->post())) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
} //ajax提交过来的会直接进行验证
...
最后,再对应的models里面增加验证的rules
...
['username', 'unique', 'targetClass' => '\backend\models\User', 'message' => '用户名已存在.'],
//targetClass目标模型类(这个不能照抄,要结合你项目注册新用户时的模型类)
['email', 'unique', 'targetClass' => '\backend\models\User', 'message' => '邮箱已存在.'],
...
貌似三者缺一都会失效,网上的教材要么只给第二步,要么只提供第三步,着实让新手有点困惑。
为此,我总结研究了下,希望可以帮助对此有困惑的人
valtrex generic lisinopril amoxicillin Buy Arimidex albuterol buy motilium buy baclofen lisinopril no rx EFFEXOR COST propecia
generic phenergan
cialis generic abilify canada
tadalafil dosage 40 mg Prednisone albuterol generic sildenafil celexa Cialis Online Amitriptyline vardenafil tablets Lasix levitra
tadalafil
prednisolone without a prescription cozaar 25 mg cafergot
tetracycline tablets buy ventolin inhaler without prescription finasteride tablets
cafergot Lisinopril tadalafil propecia minoxidil methotrexate buy retin-a canada viagra online lisinopril
Wellbutrin buy doxycycline cost of zoloft buy wellbutrin xl 5mg citalopram Buy Domperidone Online amoxicillin online
tadalafil
CAFERGOT NO RX sildenafil citrate 100mg tablets Synthroid bupropion sr price
Hi! Someone in my Myspace group shared this site with us so I
came to give it a look. I'm definitely enjoying the information. I'm bookmarking and will be
tweeting this to my followers! Exceptional blog and brilliant style
and design.
kamagra jelly
[url=http://kamagrainus.com/]buy kamagra jellies[/url]
toradol for migraine Clomid 150 buy tamoxifen buy zyban online viagra domperidone sale hydrochlorothiazide 12.5 mg FEMALE VIAGRA
lisinopril medication
viagra online tadalafil 20 mg BUY DOXYCYCLINE cost of propranolol albuterol no rx cheap cialis tetracycline antibiotics Cheapest Metformin buy zithromax 500mg Proair Albuterol Inhaler
buy prednisolone online phenergan buy tadalafil buy tetracycline without prescription viagra without prescription lisinopril 20 mg no prescription ventolin cialis canada propecia metformin
lexapro where to buy retin-a Tadalafil 5 Mg
prednisolone
prednisolone tadalafil generic for ventolin lisinopril viagra without prescription tetracycline cialis canada propecia 5mg for sale metformin phenergan buy
bupropion Buy Celebrex metformin cialis 5mg Cheap Lasix clonidine hcl .2mg viagra cheap Furosemide