In my project develop with yii 1.1.4, have this code working
controller:
/**
* Performs the AJAX validation.
* @param Products $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='products-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
view:
<?php
echo '<div class="cart-view-table-front" id="view-cart">';
echo '<h3>Il Menu che stai Ordinando</h3>';
$form=$this->beginWidget('CActiveForm', array(
'id'=>'product-form',
'enableAjaxValidation'=>false,
'action'=>Yii::app()->createAbsoluteUrl('products/uporder'),
));
now i Have update the code for Yii2
my view:
ActiveForm::begin([
'id' => 'product-form',
'action' => Url::to(['products/uporder']),
'enableAjaxValidation' => true,
]);
If analyze the code with google crhome i have this error: Uncaught TypeError: jQuery(…).yiiActiveForm is not a function(…)
my file assets is:
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* Main frontend application asset bundle.
*/
class AppAsset extends AssetBundle
{
//public $basePath = '@webroot';
//public $baseUrl = '@web';
public $sourcePath = '@bower/gaucho';
public $css = [
'css/theme.css',
'css/custom.css',
];
public $js = [
'js/jquery/jquery.min.js',
'vendor/uikit/js/uikit.min.js',
'vendor/uikit/js/components/accordion.min.js',
'vendor/uikit/js/components/autocomplete.min.js',
'vendor/uikit/js/components/datepicker.min.js',
'vendor/uikit/js/components/grid.min.js',
'vendor/uikit/js/components/lightbox.min.js',
'vendor/uikit/js/components/parallax.min.js',
'vendor/uikit/js/components/slider.min.js',
'vendor/uikit/js/components/slideset.min.js',
'vendor/uikit/js/components/slideshow.min.js',
'vendor/uikit/js/components/sticky.min.js',
'vendor/uikit/js/components/timepicker.min.js',
'vendor/uikit/js/components/tooltip.min.js',
'js/theme.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}