Yii Tutorial
Yii Useful Resources
Selected Reading
- Gii – Generating Module
- Gii – Generating Controller
- Gii – Creating a Model
- Yii - Gii
- Yii - Localization
- Yii - Authorization
- Yii - Authentication
- Yii - Error Handling
- Yii - Logging
- Yii - Aliases
- Yii - Fragment Caching
- Yii - Caching
- Yii - Testing
- Yii - Fields
- Yii - RESTful APIs in Action
- Yii - RESTful APIs
- Yii - Theming
- Yii - Database Migration
- Yii - Active Record
- Yii - Query Builder
- Yii - Data Access Objects
- Yii - Database Access
- Yii - Dependency Injection
- Yii - Configurations
- Yii - Creating a Behavior
- Yii - Behaviors
- Yii - Creating Event
- Yii - Events
- Yii - GridView Widget
- Yii - ListView Widget
- Yii - Data Widgets
- Yii - Data Providers
- Yii - Properties
- Yii - Sorting
- Yii - Pagination
- Yii - Formatting
- Yii - Files Upload
- Yii - Using Cookies
- Yii - Cookies
- Yii - Using Flash Data
- Yii - Sessions
- Yii - AJAX Validation
- Yii - Ad Hoc Validation
- Yii - Validation
- Yii - HTML Forms
- Yii - Rules of URL
- Yii - URL Routing
- Yii - URL Formats
- Yii - Responses
- Yii - HTTP Requests
- Yii - Creating Extensions
- Yii - Extensions
- Yii - Asset Conversion
- Yii - Assets
- Yii - Layouts
- Yii - Views
- Yii - Modules
- Yii - Widgets
- Yii - Models
- Yii - Using Actions
- Yii - Using Controllers
- Yii - Controllers
- Yii - Entry Scripts
- Yii - Application Structure
- Yii - Create Page
- Yii - Installation
- Yii - Overview
- Yii - Home
Yii Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Yii - AJAX Validation
Yii - AJAX Vapdation
The username vapdation should only be done on the server side because only the server has the needed information. In this case, you can use AJAX-based vapdation.
Step 1 − To enable the AJAX vapdation, modify the registration view this way.
<?php use yiiootstrapActiveForm; use yiiootstrapHtml; ?> <span class = "row"> <span class = "col-lg-5"> <?php $form = ActiveForm::begin([ id => registration-form , enableAjaxVapdation => true]); ?> <?= $form->field($model, username ) ?> <?= $form->field($model, password )->passwordInput() ?> <?= $form->field($model, email )->input( email ) ?> <?= $form->field($model, country ) ?> <?= $form->field($model, city ) ?> <?= $form->field($model, phone ) ?> <span class = "form-group"> <?= Html::submitButton( Submit , [ class => btn btn-primary , name => registration-button ]) ?> </span> <?php ActiveForm::end(); ?> </span> </span>
We should also prepare the server, so that it can handle the AJAX requests.
Step 2 − Modify the actionRegistration method of the SiteController this way.
pubpc function actionRegistration() { $model = new RegistrationForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request>post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::vapdate($model); } return $this->render( registration , [ model => $model]); }
Step 3 − Now, go to http://localhost:8080/index.php?r=site/registration, you will notice that the form vapdation is done by AJAX requests.
Advertisements