I finally have to admit defeat with this one and ask for help, I have searched for hours now and can not get this working.
Basically all I want to do is submit a form with Ajax and load a new view if the submission has been successful.
View: Connect
<?php
echo $this->renderPartial('_createaccount', array('model'=>$model, 'userID'=>$userID));
?>
View: Create Account
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array('id'=>'CreateEmailAccount',
'enableAjaxValidation'=>true,
'focus'=>array($model,'EmailAddress'),
)); ?>
<?php echo $form->errorSummary($model); ?>
<div id="error"></div>
<div class="row">
<?php echo CHtml::activeLabelEx($model,'Email Address'); ?>
<?php echo CHtml::activeTextField($model,'EmailAddress'); ?>
<?php echo CHtml::error($model,'EmailAddress'); ?>
</div>
<div class="row">
<?php echo CHtml::activeLabelEx($model,'Email Password'); ?>
<?php echo CHtml::activePasswordField($model,'EmailPassword'); ?>
<?php echo CHtml::error($model,'EmailPassword'); ?>
</div>
<div class="row_hidden">
<?php echo CHtml::activeLabel($model,'Type'); ?>
<?php echo CHtml::activeTextField($model,'Type', array('value'=>'gmail')) ?>
</div>
<div class="row_hidden">
<?php echo CHtml::activeLabel($model,'User_idUser'); ?>
<?php echo CHtml::activeTextField($model,'User_idUser', array('value'=>$userID)) ?>
</div>
<div class="row buttons">
<?php
echo CHtml::ajaxsubmitButton('Add Gmail Account',
'gmail/connect',
array("type"=>"POST",
"update" => "#wizard_tile",
"beforeSend"=> "function(){ FadeOutWizardInfo(); }",
"complete"=> "function(){ FadeInWizardInfo(); }"),
array('id'=>'creategmailaccount', 'live'=>false));
?>
</div>
<?php $this->endWidget(); ?>
</div>
Controller/Action: Connect
public function actionConnect()
{
$model = new Account();
$CComp = new CustomComponent();
$CComp->user = Yii::app()->getModule('user')->user(); // Get User
$this->performAjaxValidation($model);
if(isset ($_POST['Account']))
{
$model->attributes=$_POST['Account'];
// Save the model
//if($model->save())
// $this->redirect('index');
$this->renderPartial('connected');
Yii::app()->end();
}
$this->renderPartial('connect', array('model'=>$model, 'userID'=>$CComp->user['id']));
Yii::app()->end();
}
The view ‘connected’ is just a simple one line to prompt the user they have successful. This ‘connected’ page actually loads as an entirely new page when I press the ajaxsubmitButton. I call ‘gmail/connect’ via an ajaxLink to load the form to begin with successfully with Ajax without the page reloading, although the ajaxsubmitButton causes the page to reload.
Can anyone help me figure out why?
Thanks,
Chris
P.S. You can assume that #wizard_tile definitely exists at this point to be updated.