What I’m doing is, I use ClientSideValidation for leaving the focus of the singe edit fields. And on post I want to use a validation from the server, but I cant get it to work …
My Code looks as follows:
_form.php
<div class="form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'newsletter-form',
'enableClientValidation' => true,
'focus' => array($model, 'name'),
));
?>
<div class="row">
<?php echo $form->label($model, 'name'); ?>
<?php echo $form->textField($model, 'name', array('size' => 36, 'maxlength' => 128, 'class' => 'input_focus', 'style' => 'width: 235px')); ?>
<div style="clear:both;"></div>
<?php echo $form->error($model, 'name'); ?>
</div>
<div class="row">
<?php echo $form->label($model, 'email'); ?>
<?php echo $form->textField($model, 'email', array('size' => 36, 'maxlength' => 255, 'class' => 'input_focus', 'style' => 'width: 235px')); ?>
<div style="clear:both;"></div>
<?php echo $form->error($model, 'email'); ?>
</div>
<p style="float:left; color:#999999; font-size:11px; margin:5px 0 20px; width: 240px;">Je nach Projektphase werden wir ausgewählte Personen über weitere Schritte informieren.</p>
<div class="row buttons">
<?php echo CHtml::ajaxSubmitButton('ok', $this->createUrl('newsletter/create'), array('success'=>'js:function(data){$("#newsletter .form").hide();
$("#newsletter-confirm").show();}', array('class' => 'dialog_input_button, green_button')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
actionCreate:
public function actionCreate()
{
$model = new Newsletter;
if (isset($_POST['Newsletter'])) {
$model->attributes = $_POST['Newsletter'];
if ($model->save()) {
// do nothing
} else {
echo CActiveForm::validate($model);
Yii::app()->end();
}
} else {
$this->render('create', array(
'model' => $model,
));
}
}
At:
echo CActiveForm::validate($model);
Yii::app()->end();
it validates the model, if the save($model) fails … and it returns the json object correctly (firebug console) … but it hasnt the effect it should have … switching the id’s/classes to “error” and show the error messages.
Any suggestion?