1
Ich bin neu in Yii Rahmen, ich habe ein Arbeitsformular, das einen neuen Benutzer erstellt, derzeit das Formular umleiten zu einer Ansichtsseite, wo es eine Ansicht des eingegebenen Benutzers gibt, möchte ich Bleiben Sie nach dem Anzeigen einer Erfolgsmeldung auf der gleichen Seite. Ich möchte es mit AJAX schaffen.validiere ein Formular mit AJAX in Yii
Hier ist meine Ansicht:
<?php
/* @var $this UserController */
/* @var $model User */
$this->breadcrumbs=array(
'Users'=>array('index'),
'Create',
);
$this->menu=array(
array('label'=>'List User', 'url'=>array('index')),
array('label'=>'Manage User', 'url'=>array('admin')),
);
?>
<h1>Create User</h1>
<?php $this->renderPartial('_form', array('model'=>$model)); ?>
Hier mein Controller ist:
class UserController extends Controller
{
...
public function actionCreate()
{
$model=new User;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
...
/**
* Performs the AJAX validation.
* @param User $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
...
}
Danke, es funktioniert jetzt – user2997418