Yii2 :: Forms -> Working with ActiveForm via JavaScript

PHP side of ActiveForm, which is usually more than enough for majority of projects, is described well in the official Yii 2.0 guide (http://www.yiiframework.com/doc-2.0/guide-input-forms.html).  It is getting a bit trickier when it comes to advanced things such as adding or removing form fields dynamically or triggering individual field validation using unusual conditions. In this recipe … Read more

Yii2 :: Forms -> Using and customizing CAPTCHA

According to Wikipedia CAPTCHA means “Completely Automated Public Turing test to tell Computers and Humans Apart”. In other words, CAPTCHA provides a problem human can solve easily but computer can’t. The purpose of it is to prevent automated abuse such as posting comments containing links to malicious websites or voting for a particular candidate in … Read more

Yii2 :: Ajax Request

Examples Submitting Ajax form View file: <?php use yii; use yii\bootstrap\ActiveForm; use yii\helpers\Html; ?> <?php $form = ActiveForm::begin([ ‘action’ => [‘comments/ajax-comment’], ‘options’ => [ ‘class’ => ‘comment-form’ ] ]); ?> <?= $form->field($model, ‘comment’); ?> <?= Html::submitButton(“Submit”, [‘class’ => “btn”]); ?> <?php ActiveForm::end(); ?> Javascript: jQuery(document).ready(function($) { $(“.comment-form”).submit(function(event) { event.preventDefault(); // stopping submitting var data = … Read more