Hi,
I think it would be best if I show the code first.
Controller
public function actionAdaugaCampanie()
{
$modelCampanii = new Campanii;
$modelProduse = new Produse;
$modelStoc = new Stoc;
// Uncomment the following line if AJAX validation is needed
if(isset($_POST['ajax']) && $_POST['ajax']==='campanii-form')
{
echo CActiveForm::validate($modelCampanii);
Yii::app()->end();
}
if(isset($_POST['Campanii']))
{
$modelCampanii->attributes=$_POST['Campanii'];
if($modelCampanii->save())
$this->redirect(array('view','id'=>$modelCampanii->id));
}
$this->render('adaugaCampanie',array(
'modelCampanii'=>$modelCampanii,
'modelProduse'=>$modelProduse,
'modelStoc'=>$modelStoc,
));
}
public function actionAddProductToSession(){
echo '<script type="text/javascript">alert(11);</script>';
$modelProduse = new Produse;
$modelStoc = new Stoc;
if(isset($_POST['ajax']) && $_POST['ajax']==='produs-form')
{
echo CActiveForm::validate($modelProduse,$modelStoc);
Yii::app()->end();
}
}
View
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'campanii-form',
'enableAjaxValidation'=>true,
)); ?>
<?php echo $form->errorSummary($modelCampanii); ?>
<div class="row">
<?php echo $form->labelEx($modelCampanii,'nume'); ?>
<?php echo $form->textField($modelCampanii,'nume',array('size'=>60,'maxlength'=>255)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($modelCampanii,'data_comanda'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $modelCampanii,
'attribute' => 'data_comanda',
'htmlOptions' => array(
'size' => '10', // textField size
'maxlength' => '10', // textField maxlength
),
));
?>
</div>
<div class="row">
<?php echo $form->labelEx($modelCampanii,'data_scadenta'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $modelCampanii,
'attribute' => 'data_scadenta',
'htmlOptions' => array(
'size' => '10', // textField size
'maxlength' => '10', // textField maxlength
),
));
?>
</div>
<div class="row">
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'mydialog',
'options'=>array(
'title'=>'Adauga produs',
'autoOpen'=>false,
),
));
?>
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'produs-form',
'action'=>CHtml::normalizeUrl(array('site/AddProductToSession')),
'enableAjaxValidation'=>true,
));?>
<?php echo $form->errorSummary(array($modelProduse,$modelStoc)); ?>
<div class="form">
<div class="row">
<?php echo $form->labelEx($modelProduse,'cod'); ?>
<?php echo $form->textField($modelProduse,'cod'); ?>
<?php echo $form->error($modelProduse,'cod'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($modelProduse,'nume'); ?>
<?php echo $form->textField($modelProduse,'nume'); ?>
<?php echo $form->error($modelProduse,'nume'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($modelStoc,'cantitate'); ?>
<?php echo $form->textField($modelStoc,'cantitate'); ?>
<?php echo $form->error($modelStoc,'cantitate'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($modelStoc,'pret'); ?>
<?php echo $form->textField($modelStoc,'pret'); ?>
<?php echo $form->error($modelStoc,'pret'); ?>
</div>
</div>
<?php $this->endWidget(); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
</div>
<div class="row">
<?php echo CHtml::button('Add Product',array('onclick'=>'$("#mydialog").dialog("open"); return false;')); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($modelCampanii->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
I have two forms, one inside another. The one from inside is filled in a dialog created with jquery ui. In that dialog I want to check through ajax if the fields were filled correctly and if so, then put them into session. In the second function from controller that should’ve been called by the second form I put a javascript alert to show me if the content enters that region. I even tried an echo but it does not go there. I check the link provided to action parameter and it looks like this:
/andreea/index.php/site/AddProductToSession
What is happening here?