hi,
i have this action
public function actionCreate() {
$Pagamento = new ReservaPayment();
$Reserva = new Reserva;
$model = new Preco;
$this->actionValida();
$uid = Yii::app()->user->name == ("admin") ? " >=1" : "=" . Yii::app()->user->id;
$cod_casa = Yii::app()->getRequest()->getQuery('cod_casa');
$this->actionCalendar($cod_casa, 0);
// $this->performAjaxValidation($model);
if (isset($_POST['Preco'])) {
$model->attributes = $_POST['Preco'];
}
if ($model->save()) {
Yii::app()->user->setFlash('success', 'Everything wentfine disponibilidade!', true);
$id = Yii::app()->db->lastInsertID;
if ($model->livre == true)
unset($_POST['Reserva']);
if (isset($_POST['Reserva'])) {
$Reserva->attributes = $_POST['Reserva'];
$Reserva->idpreco = $id;
$Reserva->reserva_state = $_POST['Reserva']['reserva_state'];
$Reserva->save();
$idreserva = Yii::app()->db->lastInsertID;
Yii::app()->user->setFlash('success', 'Everything wentfine Reserva !', true);
if (isset($_POST['ReservaPayment'])) {
$Pagamento->attributes = $_POST['ReservaPayment'];
$Pagamento->idreserva = $idreserva;
$Pagamento->idpreco = $id;
$Pagamento->save();
Yii::app()->user->setFlash('success', 'Everything wentfine Reserva and Payment!', true);
}
}
}
$this->redirect(array('casa/update/', 'id' => $cod_casa, 'fromP' => '1'));
}
and this view
<?php if (Yii::app()->user->hasFlash('success')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('success') ?>
</div>
<?php endif ?>
<?php if (Yii::app()->user->hasFlash('error')): ?>
<div class="flash-error">
<?php echo Yii::app()->user->getFlash('error') ?>
</div>
<?php endif ?>
<div class="form">
<?php
$casa = $cod_casa;
if ($referer == 'preco') {
$actio = Yii::app()->createUrl('preco/update/' . $model->id . '/' . '?cod_casa=' . $casa);
$isreserva = Reserva::model()->find('(reserva_state =' . Reserva::RESERVA . " or reserva_state =" . Reserva::SINAL . ") and idpreco= " .$idpreco);
$js3 = " $('#btreserv').attr('disabled','disabled');";
if ($isreserva) {
Yii::app()->clientScript->registerScript('11', $js3, CClientScript::POS_END);
}
} else {
$actio = Yii::app()->createUrl('preco/create' . '?cod_casa=' . $casa);
}
$reserva = Reserva::model();
$pagamento = ReservaPayment::model();
$form = $this->beginWidget('CActiveForm', array(
'id' => 'preco-form',
// 'enableAjaxValidation' => true,
//'enableClientValidation' => true,
// 'clientOptions' => array('validateOnSubmit' => true,),
'action' => $actio,
));
?>
<span class="dPicker"></span><span style="float:right;color:red;">Click no calendário para alterações</span>
<div class="updaterPreco">
<ul class="operations">
<li><a class="updater" href="/index.php/preco/update/">Updater</a></li>
</ul></div>
<fieldset><legend><span>Acção</span></legend>
<div class="row">
<?php echo $form->labelEx($model, 'Opção'); ?>
<?php echo $form->dropDownList($model, 'defaccao', array('add' => 'Criar Disponibilidade', 'reserva' => 'Criar Reserva', 'del' => 'Apagar Período'), array('prompt' => 'Select Opção')); ?>
<?php echo $form->error($model, 'defaccao'); ?>
</div>
</fieldset>
<fieldset>
<legend><span>Preencha os Campos</span></legend>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary(array($model, $reserva, $pagamento)); ?>
<div class="row">
<?php //echo $form->hiddenField($model, 'cod_casa', array('type' => "text", 'value' => Yii::app()->request->getQuery('cod_casa'))); ?>
<?php echo $form->hiddenField($model, 'cod_casa', array('type' => "text", 'value' => $casa)); ?>
</div>
<div class="row">
<?php //echo $form->hiddenField($model, 'id', array('type' => "text",'value' =>Yii::app()->request->getQuery('cod_casa'))); ?>
<?php echo $form->hiddenField($model, 'id', array('type' => "text", 'value' => $casa)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'inicio'); ?>
<?php echo $form->textField($model, 'inicio', array('size' => 50, 'maxlength' => 50)); ?>
<?php echo $form->error($model, 'inicio'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'fim'); ?>
<?php echo $form->textField($model, 'fim', array('size' => 50, 'maxlength' => 50)); ?>
<?php echo $form->error($model, 'fim'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'preco'); ?>
<?php echo $form->textField($model, 'preco'); ?>
<?php echo $form->error($model, 'preco'); ?>
</div>
<div class="row">
<?php echo $form->hiddenField($model, 'livre'); ?>
</div>
<div id="divdadosreserva">
<div class="row">
<?php echo $form->hiddenField($reserva, 'id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($reserva, 'Estado'); ?>
<?php echo $form->dropDownList($reserva, 'reserva_state', CHtml::listData(ReservaState::model()->findAll(), 'id', 'state'), array('prompt' => 'Select Estado da Reserva')); ?>
<?php echo $form->error($reserva, 'Estado'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($reserva, 'idcliente'); ?>
<?php echo $form->dropDownList($reserva, 'idcliente', CHtml::listData(Proprietario::model()->findAll(), 'propid', 'proprietario'), array('prompt' => 'Select Cliente')); ?>
<?php echo $form->error($reserva, 'idcliente'); ?>
</div>
<div class="row">
<?php echo $form->hiddenField($reserva, 'idpreco'); ?>
</div>
</div>
<div id="divdadospagamento">
<div class="row">
<?php echo $form->labelEx($pagamento, 'id_tipo_pagamento'); ?>
<?php echo $form->dropDownList($pagamento, 'id_tipo_pagamento', CHtml::listData(TipoPagamento::model()->findAll(), 'id', 'tipo_pagamento'), array('prompt' => 'Select Meio Pagamento')); ?>
<?php echo $form->error($pagamento, 'id_tipo_pagamento'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($pagamento, 'id_pagamento'); ?>
<?php echo $form->textField($pagamento, 'id_pagamento', array('size' => 20, 'maxlength' => 20)); ?>
<?php echo $form->error($pagamento, 'id_pagamento'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($pagamento, 'valor'); ?>
<?php echo $form->textField($pagamento, 'valor'); ?>
<?php echo $form->error($pagamento, 'valor'); ?>
</div>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('id' => 'btreserv', 'class' => 'but')); ?>
</div>
<?php
$this->endWidget();
Yii::import('application.controllers.PrecoController');
PrecoController::actionCalendar($casa, $model->id);
?>
<?php
$pth= Yii::app()->createUrl('reserva/ajaxform');
?>
</fieldset>
</div><!-- form -->
<?php
if ($referer == 'preco') {
echo $this->renderPartial('../reserva/admin', array('model' => new Reserva(), 'cod_casa' => $model->cod_casa, 'idpreco' => $model->id));
//echo $this->renderPartial('../prereserva/admin', array('model' => new Prereserva(), 'cod_casa' => $model->cod_casa, 'idpreco' => $model->id));
}
?>
I can’t see the validation errors.
this is the rules.
return array(
array('cod_casa,preco,inicio, fim,defaccao', 'required'),
array('ano, n_semana, cod_casa, preco', 'numerical', 'integerOnly' => true),
array('nm_mes, inicio, fim, reservar', 'length', 'max' => 50),
array('livre, promo, paga,defaccao', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, ano, nm_mes, n_semana, cod_casa, inicio, fim, preco, livre, reservar, promo, paga,defaccao', 'safe', 'on' => 'search'),
);