Yii: Submit a value to different model - php

Here's a newbie question related to my latest exercise with Yii Framework.
I have a following structure in the database:
CREATE TABLE location(
id INTEGER PRIMARY KEY NOT NULL,
location TEXT);
CREATE TABLE parameter(
id INTEGER PRIMARY KEY NOT NULL,
name TEXT,
value TEXT);
CREATE TABLE temperature(
id INTEGER PRIMARY KEY NOT NULL,
locationId INTEGER,
value REAL NOT NULL,
createDate DATETIME NOT NULL,
FOREIGN KEY(locationId) REFERENCES location(id));
CREATE INDEX idx1_temperature ON temperature (createDate);
I'm trying to create a view containing both location data in a grid, but also a functionality to change a certain value in parameter-table. In practice I would have a list of all possible locations in a grid, in addition to a possibility to change the parameter.value where parameter.name="CURRENT_LOCATION".
What I've gotten so far is:
location/admin.php generating a view:
...
<h2>Change current location</h2>
<?php echo $this->renderPartial('_para', array('model'=>Parameter::model()->find('name="current_location"'))); ?>
<h2>Modify locations</h2>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'location-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
'location',
array(
'class'=>'CButtonColumn',
),
),
));
...
location/_para.php for embedding a form:
<?php
/* #var $this ParameterController */
/* #var $model Parameter */
/* #var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'parameter-form',
'enableAjaxValidation'=>false,
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'value'); ?>
<?php //echo $form->textField($model,'value'); ?>
<?php echo $form->dropDownList($model,'value',CHtml::listData(Location::model()->findAll(), 'id', 'location')); ?>
<?php echo $form->error($model,'value'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
So, what would need is to Save(=update) a given parameter-row, but I just seem not to get it right. I have debugged so far that it seems like the Submit Button causes the Location-controller's actionAdmin-function to be executed. That would be fine by me, if I just could instruct there to save the Parameter-record instead of the Location.
Here's the actionAdmin-function from LocationController.php:
public function actionAdmin()
{
$model=new Location('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Location']))
{
$model->attributes=$_GET['Location'];
}
if(isset($_POST['Parameter']))
{
$model->attributes=$_POST['Parameter'];
if($model->save())
{
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('admin',array(
'model'=>$model,
));
}
I see a lot to posts covering multi model forms and such, but I just cannot get a grip on this. It may very well be that I'm trying to accomplish this in a totally wrong way.
So, punch me to right direction, please.

Okay so, I think the best thing is to put the method for updating the Parameter in the ParameterController. That makes it easier to implement and is a bit cleaner.
So to do that, change the form code to this:
You might need to adjust the action in the form for it to work, e.g. /admin/parameter/update
<?php
/* #var $this ParameterController */
/* #var $model Parameter */
/* #var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'parameter-form',
'enableAjaxValidation'=>false,
// Check that the action method below is correct
'action' => array('/parameter/update', 'id' => $model->id),
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'value'); ?>
<?php //echo $form->textField($model,'value'); ?>
<?php echo $form->dropDownList($model,'value',CHtml::listData(Location::model()->findAll(), 'id', 'location')); ?>
<?php echo $form->error($model,'value'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
If you have an existing update method in your ParameterController, see if it works as is. If it doesn't or you don't have the update method, try something like this:
public function actionUpdate($id)
{
$model = Parameter::model()->findByPk($id);
if(isset($_POST['Parameter']))
{
$model->attributes=$_POST['Parameter'];
if($model->update())
{
// Below redirects to the previous URL
$this->redirect(Yii::app()->request->urlReferrer);
}
}
}
I changed $model->save() to $model->update() because that won't call the validation rules and make it return false. If you want to validate for some reason, you will need to change the rule so that name and value are only required when creating a new parameter, like this:
array('name, value', 'required', 'on' => 'create'),
And then when you create your new Parameter, you would need to do $model = new Parameter('create');

Related

How to save input in yii to database

I have this code Im trying to save the content and the title from a form I made..It has an id that autoincrement the id number adds in the database but the title and the content isn't/cant be save in the database. Can you please check my code if I've done something wrong? or what I'm lacking at.
Here is my model ContentForm.php
<?php
class ContentForm extends CActiveRecord{
public $content;
public $title;
public function tableName(){
return 'tbl_content';
}
public function attributeLabels()
{
return array(
'contentid' => 'contentid',
'content' => 'content',
'title' => 'title',
// 'email' => 'Email',
// 'usrtype' => 'Usrtype',
);
}
Here is my view content.php
<div>
<p>User: <a href="viewuserpost">
<?php
echo Yii::app()->session['nameuser'];
?>
</a>
</p>
</div>
<h1>Content</h1>
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'contact-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
));
?>
Title:
<div class="row">
<?php
echo $form->textfield($model,'title');
?>
</div>
</br>
Body:
<div class="row">
<?php
echo $form->textArea($model,'content',array('rows'=>16,'cols'=>110));
?>
</div>
<div class="row buttons">
<?php
echo CHtml::submitButton($model->isNewRecord? 'Create':'Save');
?>
</div>
<?php $this->endWidget(); ?>
and here is my content action in my sitecontroller.php
public function actionContent(){
$model=new ContentForm;
if(isset($_POST['ContentForm'])) {
$model->attributes=$_POST['ContentForm'];
if($model->save())
$this->redirect(array('content','contentid'=>$model->contentid));
$this->redirect(array('content','title'=>$model->title));
$this->redirect(array('content','content'=>$model->content));
}
$this->render('content',array('model'=>$model));
}
Please help.
Remove
public $content;
public $title;
from your class.
Yii uses PHP magic methods. And when you add attributes to your class, PHP doesn't call them but references to your explicitly written attributes.
Moreover, you should add some validation, if you use $model->attributes=$_POST['ContentForm'];. Another variant is to use unsecure $model->setAttributes($_POST[ContentForm], false) where false tells Yii to set all attributes, not only that are considered safe.
Note, that attributes is not real Model attribute, this is virtual attribute accessed through magic methods.
Also, you don't need three redirects. This is HTTP redirect to other page. This time, you just should just specify route to model view action and its parameter that is id, for example. Like this $this->redirect(array('content/view','id'=>$model->contentid));.
Of course, simplest way for you is to create new model and controller with actions using Gii.
you may missed rules , add this in your model ContentForm.php
public function rules()
{
return array(
array('content,title', 'safe'),
);
}
For more about model validation
http://www.yiiframework.com/wiki/56/reference-model-rules-validation/

DropDownList effects a ClistView in Yii

I am still very new to this Yii framework, and I would like assistance with this code. I currently manage to get a dropdownlist dependent on another dropdownlist but I can't seem to get the dropdownlist to effect what gets displayed in the ClistView.
profile Controller
/* add a team message submitted by the coach of the team */
public function actionAddTeamMessage($id)
{
/* check if team and message aren't null */
if(isset($_POST['teamId']['addTeamMessage']))
{
try
{
/* creates a new message */
$teamModel = new TeamMessage;
$teamModel->teamId = $_POST['teamId'];
$teamModel->content = $_POST['addTeamMessage'];
$teamModel->sendTime = new CDbExpression('NOW()');
$teamModel->save();
}
catch(Exception $e)
{
echo "Unable to save.";
}
}
/* render the profile page for the current user */
$user=User::model()->findByPk($id);
$this->render('profile', array(
'model' => $user));
}
/* will handle functionality for the user dropdownlist ajax
* under contructions
*/
public function actionDisplayMessage()
{
$data = TeamMessage::model()->findAll('teamId=:teamId', array(
':teamId'=>(int) $_POST['teamId']
)
);
$data=CHtml::listData($data,'id', 'content');
echo "<option value=''>Select Message</option>";
foreach($data as $value=>$content)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($content),true);
//TODO still being tested.
/* for ClistView still debugging */
/*$dataProvider=new CActiveDataProvider('Player', array(
'criteria'=>array(
'condition'=>'teamId=:teamId',
)));*/
}
View Profile
<!-- Would allow user to access specific team messages and control how much gets display.
still under construction. -->
<div class="row">
<?php
echo CHtml::dropDownList("teamId", 'id', Chtml::listData($model->memberOfTeams, 'id', 'teamName'),array(
'empty'=>'Select Team',
'ajax'=>array(
'type'=>'POST', // request type
'url'=>CController::createUrl('DisplayMessage'),
'update'=>'#teamMessages', // selector to update
'data'=>array('teamId'=>'js:this.value'),
)
)
);
?>
<?php
echo CHtml::dropDownList('teamMessages','',array(),array('empty'=>'Select Message'));
/*$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_viewTeamMessage',
'id'=>'ajaxListView',
));*/
?>
</div>
As you can see in the cListView. I was debating on creating a _viewTeamMessage which will display the team message + sendtime. But I realize, I wouldn't be able to pass a dataprovider without re rendering the page, and i am trying to avoid heading into that direction.
You could pull your Team messges out into a partial view and then just use a render partial to render just the messages into your page usig Ajax. If the partial view is named _teamMessages.php it would look something like this (untested):
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_viewTeamMessage',
'id'=>'ajaxListView',
));
Then you modify your profile view to look like:
<!-- Would allow user to access specific team messages and control how much gets display.
still under construction. -->
<div class="row">
<?php
echo CHtml::dropDownList("teamId", 'id', Chtml::listData($model->memberOfTeams, 'id', 'teamName'),array(
'empty'=>'Select Team',
'ajax'=>array(
'type'=>'POST', // request type
'url'=>CController::createUrl('DisplayMessage'),
'update'=>'.team-messages', // selector to update
'data'=>array('teamId'=>'js:this.value'),
)
)
);
?>
<div class="team-messages">
<?php
$this->renderPartial('_teamMessages',
array('dataProvider'=>$dataProvider))
?>
</div>
</div>
Then finally you change your controller to something like this:
public function actionDisplayMessage()
{
/* REMOVE
$data = TeamMessage::model()->findAll('teamId=:teamId', array(
':teamId'=>(int) $_POST['teamId']
)
);
$data=CHtml::listData($data,'id', 'content');
echo "<option value=''>Select Message</option>";
foreach($data as $value=>$content)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($content),true);
*/
// still being tested.
$dataProvider=new CActiveDataProvider('Player', array(
'criteria'=>array(
'condition'=>'teamId=(int) $_POST['teamId']',
)));
$this->renderPartial('_teamMessages', array('dataProvider'=>$dataProvider);
}
this should just cause the message widget to be recreated instead of the whole page.

Import csv to mysql using Yii framework

I have a problem with uploading csv file to database. This is my view:
<?php
$this->breadcrumbs = array(
__('People') => array('/contacts'),
__('Persons') => array('admin'),
__('Manage'),
);?>
<h1><?php echo __('People'); ?> <small><?php echo __('import contacts'); ?></small></h1><br/>
<div class="form">
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'service-form',
'enableAjaxValidation'=>false,
'method'=>'post',
'type'=>'horizontal',
'htmlOptions'=>array(
'enctype'=>'multipart/form-data'
)
)); ?>
<fieldset>
<?php echo $form->errorSummary($model, 'Opps!!!', null, array('class'=>'alert alert-error span12')); ?>
<div class="control-group">
<div class="span4">
<div class="control-group <?php if ($model->hasErrors('postcode')) echo "error"; ?>">
<?php echo $form->labelEx($model,'file'); ?>
<?php echo $form->fileField($model,'file'); ?>
<?php echo $form->error($model,'file'); ?>
</div>
</div>
</div>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'icon'=>'ok white', 'label'=>'UPLOAD')); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset', 'icon'=>'remove', 'label'=>'Reset')); ?>
</div>
</fieldset>
<?php $this->endWidget(); ?>
</div><!-- form -->
This is my model:
<?php
class UserImportForm extends CFormModel
{
public $file;
/**
* #return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('file', 'file',
'types'=>'csv',
'maxSize'=>1024 * 1024 * 10, // 10MB
'tooLarge'=>'The file was larger than 10MB. Please upload a smaller file.',
'allowEmpty' => false
),
);
}
/**
* #return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'file' => 'Select file',
);
}
}
?>
And this is my function in Controller
public function actionImportCSV()
{
$model=new UserImportForm;
if(isset($_POST['UserImportForm']))
{
$model->attributes=$_POST['UserImportForm'];
if($model->validate())
{
$csvFile=CUploadedFile::getInstance($model,'file');
$tempLoc=$csvFile->getTempName();
$sql="LOAD DATA LOCAL INFILE '".$tempLoc."'
INTO TABLE `contacts`
";
$connection=Yii::app()->db;
$transaction=$connection->beginTransaction();
try
{
$connection->createCommand($sql)->execute();
$transaction->commit();
}
catch(Exception $e) // an exception is raised if a query fails
{
echo "<pre>";
print_r($e);
echo "</pre>";
exit;
$transaction->rollBack();
}
$this->redirect(Yii::app()->createUrl("/contacts/importCSV"));
}
}
$this->render("importcsv",array('model'=>$model));
}
And I have a problem with LOAD DATA, cause mySQL version don't support LOAD DATA. Anyone knows how can I replace load data to import csv file?
Follow the instructions at:
https://github.com/Ardem/yii-importcsv-extension
I followed the simple steps described in readme.md file having the 3 simple steps and it worked like a breeze.
If you are on a version of MySQL tat does not support LOAD DATA, then you are on a very old version indeed. The current online documentation includes LOAD DATA in every mentioned version, though the LOCAL clause is only supported as far back as 3.22.6.
Maybe the real problem is that if you do not specify the FIELDS clause it treats the file as if
FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\'
LINES TERMINATED by '\n' STARTING BY ''
were specified. That is a TAB separated values file in Unix(Linux) text format. To make it comma separated, specify:
LOAD DATA LOCAL INFILE 'data.txt' INTO TABLE tbl_name
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"';
And if you are expecting files from a Windows machine you might want to include
LINES TERMINATED BY '\r\n'
after the FIELDS clause.

zf2 form validation (zfcAdmin and BjyAuthorize related)

I'm facing validation problems integrating my custom module in zfcAdmin and BjyAuthorize.
My form class:
...
$formOptions = $this->settings->getFormSettings();
foreach ($formOptions as $field){
if (isset($field['field']))
$this->add($field['field']);
}
...
My filter class:
$formOptions = $this->settings->getFormSettings();
foreach ($formOptions as $filter){
if (isset($filter['filter']))
$this->add($filter['filter']);
}
...
Fields, filters and other options are retrieved from config file.
Basically everything works fine: form data can be added, edited or deleted from db.
Also after the zfcAdmin module installation no problem rose. Everything works fine using both 'site/mymodule' route and 'site/admin/mymodule' route: i can still add, edit and delete items from db.
Here the problem: I need some form elements (a Select in this particular case) editable/viewable only by administrator. (I can write a new controller/entity class 'ad hoc' for admin but i would like to use the same code for the whole site.)
I installed and configured bjyoungblood/BjyAuthorize module: it allowed me to display some form elements/fields only to admin but when i'm in edit mode a form validation error is displayed: "Value is required and can't be empty"
Here the code:
//view/mymodule/mymodule/update.phtml
<div id="page" style="margin-top: 50px;">
<?php if (isset($this->messages) && count($this->messages) > 0 ): ?>
<?php foreach ($this->messages as $msg): ?>
<div class="alert alert-<?php echo $this->escapeHtmlAttr($msg['type']); ?>">
<?php if (isset($msg['icon'])) echo '<i class="'.$this->escapeHtmlAttr($msg['icon']).'"></i> '; ?><?php echo $this->escapeHtml($msg['message']); ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php
$title = 'Edit Item';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<?php
$form = $this->form;
$form->setAttribute('action', $this->url($this->route . 'mymodule/update', array('action' => 'update', 'id' => $this->id )));
$form->prepare();
$form->setAttribute('method', 'post');
$input = $form->getInputFilter();
?>
<?php echo $this->form()->openTag($form) ?>
<dl class="zend_form">
<?php foreach ($form as $element): ?>
<?php
//CHECK USER PRIVILEDGES
$elName = $element->getName();
$elResource = isset($this->form_options[$elName]['auth']) ? $this->form_options[$elName]['auth']['resource'] : "userresource";
$elPrivilege = isset($this->form_options[$elName]['auth']) ? $this->form_options[$elName]['auth']['privilege'] : "view";
//SHOW THE ELEMENT IF ALLOWED
if($this->isAllowed($elResource, $elPrivilege)):
?>
<?php if ($element->getLabel() != null): ?>
<dt><?php echo $this->formLabel($element) ?></dt>
<?php endif ?>
<?php if ($element instanceof Zend\Form\Element\Button): ?>
<dd><?php echo $this->formButton($element) ?></dd>
<?php elseif ($element instanceof Zend\Form\Element\Select): ?>
<dd><?php echo $this->formSelect($element) . $this->formElementErrors($element) ?></dd>
<?php else: ?>
<dd><?php echo $this->formInput($element) . $this->formElementErrors($element) ?></dd>
<?php endif ?>
<?php else: ?>
<?php
?>
<?php endif ?>
<?php endforeach ?>
</dl>
<?php echo $this->form()->closeTag() ?>
</div>
<div class="clear-both"></div>
My controller action
//controller
public function updateAction(){
$messages = array();
$id = (int)$this->getEvent()->getRouteMatch()->getParam('id');
$form = $this->getServiceLocator()->get('FormItemService');
$itemMapper = $this->getItemMapper();
$item = $itemMapper->findById($id);
$form->bind($item);
$request = $this->getRequest();
if($request->isPost()){
$form->setData($request->getPost());
if ($form->isValid()) {
die('c');//never here
$service = $this->getServiceLocator()->get('mymodule\Service\Item');
if ( $service->save($form->getData()) )
{
$messages[] = array(
'type' => 'success',
'icon' => 'icon-ok-sign',
'message' => 'Your profile has been updated successfully!',
);
}
else
{
$messages[] = array(
'type' => 'error',
'icon' => 'icon-remove-sign',
'message' => 'Profile update failed! See error messages below for more details.',
);
}
}else{
var_dump($form->getMessages());//Value is required and can't be empty
}
}
return array(
'messages' => $messages,
'form' => $form,
'id' => $id,
'form_options' => $this->getServiceLocator()->get('mymodule_module_options')->getFormSettings(),
'route' => $this->checkRoute($this->getEvent()->getRouteMatch()->getmatchedRouteName())
);
}
If user is not allowed to view the resource, the element is not echoed. So $request->getPost() has no value for that form element and an error is returned by isValid().
Has anyone solved a similar problem or can anyone point me to the right direction?
Thanks
The problem is that you don't do any security check in your FormFilter class, where you define your required fields.
The $form->isValid() function checks the posted data against those filter elements. So it's not enough to prevent the 'echo field' in your view, you still need to apply the security check to the filter element.
One other approach would be to make two forms one for the front end and one for the admin. Since the one for the admin will have the same fields plus one extra select field you can make the admin form extends the front end one. E.g.
class myForm
{
public function __construct(...)
{
// add fields and set validators
}
}
and the admin form could be:
class MyAdminForm extends myForm
{
public function __construct(...)
{
parent::__construct(...);
// add the extra field and extra validator
}
}
In that way even if you edit the front end form (or validators) the back end will always be up to date.
Hope this helps :),
Stoyan

Infinite loop trying to validate/save

I'm using Yii framework to create a really simple 1 text-area field and 2 hidden inputs with predefined values sent from the server.
The way it should work is as expected, I mean, you write something on that text-area and you click on the send button. An ajax validation is made (only requisite for the text-area is that is shouldn't be empty) and if validated, save the data and redirect to some other page.
The problem is that it won't save any data if validation error was triggered.
I mean, if I go to the page, write something and hit on the send button, data will be saved and I'll be redirected correctly. But if I go to the page, hit the send button (without typing anything in the text-area), wait for the error to appear (note that this is done via ajax, so no page-reload here), write something and hit send again Yii is going to start making a request after a request in an infinite loop.
I already have checked the data being sent, and everything is fine (both data and action-url).
Here is my Controller code
public function actionView($id)
{
$user = Usuario::model()->findByAttributes(
array(
'nick'=>Yii::app()->user->getId()
)
);
$dataProvider=new CActiveDataProvider('Mensaje', array(
'criteria'=>array(
'with'=>array('usuario', 'usuario.detallesusuario'),
'condition'=>'Tema_idtema='.$id
),
'pagination'=>array(
'pageSize'=>1000,
),
));
$this->render('view',array(
'model'=>$this->loadModel($id),
'usuario_id'=>$user->idusuario,
'tema_id'=>$id,
'dataProvider'=>$dataProvider,
));
}
public function actionCreateMessage(){
$model=new Mensaje;
$this->performAjaxValidation($model);
if(isset($_POST['Mensaje']))
{
$model->attributes=$_POST['Mensaje'];
$model->fecha_hora=new CDbExpression('NOW()');
$model->save();
$this->redirect(array('view', 'id'=>$model->Tema_idtema));
}
}
And the code from the View
<?php
$model = new Mensaje();
echo $this->renderPartial('_mensaje_form', array(
'model'=>$model,
'usuario_id'=>$usuario_id,
'tema_id'=>$tema_id,
),
false, //return instead of echo
true //post-process
);
?>
Here is the "_mensaje_form" code
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'mensaje-form',
'action'=>CHtml::normalizeUrl(array('tema/createMessage')),
'enableAjaxValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>false,
'validateOnType'=>false,
),
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row" style="margin:20px 5px 0 176px;">
<?php echo $form->labelEx($model,'mensaje'); ?>
<?php echo $form->textArea($model,'mensaje',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'mensaje'); ?>
<?php echo $form->hiddenField($model, 'Tema_idtema', array('value'=>$tema_id)); ?>
<?php echo $form->hiddenField($model, 'Usuario_idusuario', array('value'=>$usuario_id)); ?>
</div>
<div class="row buttons" style="margin:-3px 0 -8px 176px;">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Responder' : 'Guardar'); ?>
</div>
<?php $this->endWidget(); ?>
Any idea why I'm getting that loop?
This might help you,
http://www.yiiframework.com/forum/index.php/topic/10427-ajax-clientscript/
in your view, the last parameter "true" in renderPartial may be the problem.
My guess (a bit long shot) that form id in your preformAjaxValidation() might be wrong, so it causes the loop! since it won't get in the body of the if and hence executes Yii::app()->end(); !!
Check it in your controller:
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='exact-form-id')//should be mensaje-form
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}

Categories