Good morning,
first of all the important scripts. Error happens when calling index.php?r=site/index
app/controllers/site/IndexAction.php
[PHP]class IndexAction extends CAction
{
public function run()
{
$this->controller->render('index');
}
}[/PHP]
app/views/site/index.php
[PHP]<h1 class="alt">Output b4 widget</h1>
<hr />
<?php $this->widget(‘ext.smstrade.ESmsTrade’); ?>[/PHP]
app/extensions/smstrade/ESmsTrade.php (ESmsTrade extends CWidget)
[PHP]public function run()
{
$form = $this->createForm();
$this->handleForm($form);
}
// This is where i enable ajax validation
private function createForm()
{
// ...some unimportant code...
$form->activeForm = array('class' => 'CActiveForm',
'id' => self::ID_FORM,
'enableAjaxValidation' => true);
return $form;
}
private function handleForm($form)
{
$this->performAjaxValidation($form);
//...[code code code]...
$this->render('form', array('form' => $form));
}
private function performAjaxValidation($form)
{
if(isset($_POST['ajax']) && $_POST['ajax'] == self::ID_FORM)
{
echo CActiveForm::validate($form->model);
Yii::app()->end();
}
}[/PHP]
As you can see my view already has some content before it calls the widget. Actually this isn’t a big problem unless it comes to an ajax validation call which is sending a POST request to index/site.
So the response contain the content of the view till the widget call, appended by the JSON code.
My question is: How can i avoid such a behavior? The only way i can think of is calling the widget directly before i render any HTML code - but thats not the way how it is supposed to work.