Hello Yii ppl, im having a little problem when usiond ajaxsubmitbutton inside my form…
FORM within view rendered in RUN action
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'evento-form',
//'action' => Yii::app()->createUrl('evento/guardarEvento'),
'enableAjaxValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>false,
'validateOnChange'=>true,
),
'enableClientValidation'=>true,
'htmlOptions'=>array(
'enctype'=>'multipart/form-data'
),
));
$permiso = $model->getPermisosUsuarioLogeado();
?>
<?php echo $form->errorSummary($model); ?>
//rest of the form
<div class="row-fluid submit span10" style="bottom:10px;position:absolute;margin-top:50px;border-top: 2px solid #8a0a49;padding-top: 10px;">
<div class="span6">
<?php
if (($permiso >= 5 ) || ($permiso == -1)) {
echo CHtml::ajaxSubmitButton('Salvar',
CHtml::normalizeUrl(array('evento/guardarEvento','render'=>true)),
array(
'type' => 'POST',
'datatype' => 'json',
'data'=> '$("form").serialize()',
'success'=>'function(data){
$("#AjaxLoader").hide();
}',
'beforeSend'=>'function(){
alert(data);
$("#AjaxLoader").show();
}',
),
array(
'id'=>'ajaxSubmitBtn',
'name'=>'ajaxSubmitBtn',
)
);
// $this->widget('bootstrap.widgets.TbButton', array(
// 'label'=>'Guardar',
// 'type'=>'wisboo', // null, 'primary', 'info', 'success', 'warning', 'danger', 'inverse' or 'wisboo'
// 'size'=>'', // null, 'large', 'small' or 'mini'
// 'buttonType' =>'submit',
// ));
RUN function on WIDGET
public function run()
{
$usuario = Usuario::model()->getUsuarioSession();
if(isset($_POST['ajax']) && $_POST['ajax']==='evento-form')
{
echo CActiveForm::validate($this->model);
Yii::app()->end();
}
if(isset($_POST['Evento']))
{
// collects user input data
$this->model->attributes=$_POST['Evento'];
// validates user input and redirect to previous page if validated
$fechaHoy = date('Y-m-d H:i:s');
$this->model->fechaCreacion = new CDbExpression("NOW()");
$fechaHoraDeEvento = $this->fechaEntera . date('H:i:s');
$this->model->fechahoraDelEvento = new CDbExpression("NOW()");//OBTENER DEL FORMULARIO
if($this->model->validate()) {
$this->model->fueNotificado = 1;
$this->model->save();
$participacion = Participacion::model()->findAll('EVENTO_idEVENTO = :idEvento', array('idEvento' => $this->model->getPrimaryKey()));
if ($participacion == NULL)
{
$participacion = new Participacion();
$participacion->USUARIO_idUSUARIO = $usuario->id;
$participacion->EVENTO_idEVENTO = $this->model->getPrimaryKey();
/*if ($this->idtipo == 14){
$this->model->COMISION_idCOMISION;
}
if ($this->idtipo == 15){
$this->model->GRUPO_idGRUPO;
}
if ($this->idtipo == 22){
$this->model->CURSO_idCURSO;
}*/
$participacion->tipo_participacion = 17;
$participacion->descripcion = 'descripcion';
$participacion->asistencia = 0;
$participacion->aprobado = 1;
$participacion->save();
}
}
//FUE AÑADIDO
return;
}
// displays the form
$this->render("crearEventoThumb",array(
'model' => $this->model,
'arrayEventosPosibles' => $this->tiposEvento,
'fecha'=> $this->fechaEntera));
}
model save works perfectly, the thing is wether use ajaxsubmitbutton or tbButton, refreshes my whole page.
please help in this one!
ive tried everything so far (i realize the ajaxsubmitbutton aims to other action, but doesn’t make a change anyways… the widget is a selfbuild widget, not an extension,
cheers