Good morning everybody.
I have a view with two listboxes. The first is automatically filled, while the second, initially empty, is dynamically populated through three AJAX/Jquery methods (which simply copy the selected content from the first listbox to the second).
The whole form is bound to a CFormModel $model. The first listbox is paired to the $model->cqCompany field, and the second one is paired to the $model->cqCompanyCopy field.
The second listbox never appears in $_POST, and I cannot understand why.
view:
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
$this->layout='//layouts/column1';
$this->menu=array();
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array('id'=>'cqForm')); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php
echo $form->label($model,'cqCompany');
echo $form->listBox($model, 'cqCompany', CompanyHash::getInstance()->getCompanies(), array('empty' => array('-1'=>'ALL COMPANIES\''),'multiple' => 'multiple', 'size'=>'8'));
echo "<br>";
echo CHtml::button('Add Selected', array('onclick'=>'add();'));
echo CHtml::button('Delete Selected',array('onclick'=>'delete();'));
echo CHtml::button('Delete All', array('onclick'=>'deleteAll();'));
echo "<br>";
echo $form->label($model,'cqCompanyCopy');
echo $form->listBox($model, 'cqCompanyCopy', array(), array('size'=>'8'));
?>
</div>
<div class="row submit">
<?php echo CHtml::submitButton('Scarica'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
model:
<?php
/**
* CustomQueryForm class
*/
class CustomQueryForm extends CFormModel
{
public cqYear;
public $cqCompany;
public $cqCompanyCopy;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
array('cqCompanyCopy', 'safe'),
array('cqYear, cqCompanyCopy', 'required'),
);
}
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'cqCompany'=>'Companies',
'cqCompanyCopy'=>'Selected Companies',
'cqYear'=>'Year',
);
}
}
in the controller there is the following action:
public function actionCustomquery(){
$cqForm = new CustomQueryForm();
if (isset($_POST['CustomQueryForm'])){
$cqForm->attributes = $_POST['CustomQueryForm'];
if ($cqForm->validate()){
$helper = new ReportHelper($cqForm);
return $helper->export();
}
}
$this->render('customquery', array('model'=>$cqForm));
}
Could you help me to understand the reason why $_POST[‘CustomQueryForm’] doesn’t contain the cqCompanyCopy field?
Thank you in advance.