Hi all,
I’m two days trying solve this, but I have no success.
I have a page _form.php for my identificacaoEmigrante.php model and a page _form.php for my filiacao.php model.
In identificacaoEmigrante model, I have fields like:
-
IdEmigrante
-
nome
-
idConjuge
-
nomeConjuge
-
idFiliacao (FK)
and in filiacao model, I have fields like:
-
idFiliacao (PK)
-
nomeMae
-
nomePai
From this, I wanna save the identificacaoEmigrante _form in $_SESSION variables for after get these values in other pages.
I have an interface like this:
5535
When I click on the button with label: "Adicionar nova filiacao", I wanna go to the filiacao _form and fill that form and
when I come back, I want that identificacaoEmigrante _form be filled with previously entered data. IE, I’m filling identificacaoEmigrante _form and filiacao don’t exists yet, so, I need click on button “adicionar nova filiacao” and call filiacao _form through onClick of TbButton event and fill that fields. When I come back from the filiacao _form, I wanna that fields of identificacaoEmigrante _form be filled with the $_SESSION variables.
My identificacaoEmigrante _form.php:
<div class="form container">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'identificacao-emigrante-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="container">
<div class="row">
<?php echo $form->labelEx($model,'idEmigrante'); ?>
<?php echo $form->textField($model,'idEmigrante', array('id'=>'idE')); ?>
<?php echo $form->error($model,'idEmigrante'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'nome'); ?>
<?php echo $form->textField($model,'nome',array('size'=>60,'maxlength'=>64, 'id'=>'nome')); ?>
<?php echo $form->error($model,'nome'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'dtNasc'); ?>
<?php echo $form->textField($model,'dtNasc'); ?>
<?php echo $form->error($model,'dtNasc'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'idConj'); ?>
<?php echo $form->textField($model,'idConj',array('size'=>10,'maxlength'=>10)); ?>
<?php echo $form->error($model,'idConj'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'nomeConj'); ?>
<?php echo $form->textField($model,'nomeConj',array('size'=>60,'maxlength'=>64)); ?>
<?php echo $form->error($model,'nomeConj'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'idFiliacao'); ?>
<?php
if ($model->isNewRecord) {
$this->widget('bootstrap.widgets.TbSelect2', array(
'model' => $modelFiliacao,
'attribute' => 'idFiliacao', //'id' CAMPO A BUSCAR
'data' => CHtml::listData($modelFiliacao->findAll(), 'idFiliacao', 'nomePai', 'nomeMae'),
'htmlOptions' => array('placeholder' => 'Selecione a Filiação',),
)); //listData($modelDESEJADO->findAll(), 'CAMPO A SER MODIFICADO', 'CAMPO A MOSTRAR NO COMBOBOX')
} else if (!$model->isNewRecord) {
$qry = "SELECT filiacao.idFiliacao, nomePai, nomeMae from filiacao, identificacaoEmigrante where filiacao.idFiliacao = identificacaoEmigrante.idFiliacao";
$result = Yii::app()->db->createCommand($qry)->queryAll();
$data=CHtml::listData($result, 'idFiliacao', 'nomePai', 'nomeMae');
$this->widget('bootstrap.widgets.TbSelect2', array(
'model' => $model,
'attribute' => 'idFiliacao', //'id' CAMPO A BUSCAR
'data' => CHtml::listData($modelFiliacao->findAll(), 'idFiliacao', 'nomePai', 'nomeMae'),
'htmlOptions' => array(
'options' => $data,
),
));
}
?>
<?php
$this->widget(
'bootstrap.widgets.TbButton',
array(
'type' => 'primary',
'buttonType' => 'ajaxLink',
'label' => 'Adicionar nova Filiação',
'htmlOptions'=> array(
'onClick'=> 'saveSession()',
)
));
?>
<?php echo $form->error($model,'idFiliacao'); ?>
</div>
<div class="row">
<?php
$this->widget(
'bootstrap.widgets.TbButton',
array(
'type' => 'primary',
'buttonType' => 'submit',
'label' => 'OK',
)
);
?>
</div>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
My siteController.php:
...
public function actionMyActionName() {
Yii::app()->session['idE'] = $_POST['idE'];
echo json_encode(array("ide"=>$_POST['idE']));
}
...
My Javascript (a.js) code:
function saveSession() {
$.ajax({
type: "POST",
//url: "/museu_emigracao/index.php?r=site/savesession",
url: '/museu_emigracao/index.php?r=site/myActionName',
data: {
idE : $("#idE").val()
},
success: function (data) {
console.log(data.idE);
},
error: function (data) {
alert(data + 'erro');
},
dataType: null
});
}
I’ve tested dataType: JSON and others like “text”, but my code doesn’t return nothing, therefore a null value should be correct.
My code is testing just idEmigrante field now, but without success.
The data.idE return undefined, but in chrome’s debug, it appears with the value (idE: 123).
5536
Any suggestions?
Thanks.