0

I can access the registration form which appears in a model window via ajax on any page as coded in the menu layout . I need some thing on click of submit button of registration form it should get display a thank you message which is also via ajaxin the same div as that of wherein the registration form appears registratiincontrooler

 if ($model->save()) {echo "thank you for  registration";return;      }    

registration view

   <?php
    /* @var $this UserProfileController */
   /* @var $model UserProfile */

   $this->breadcrumbs=array(
    'User Profiles'=>array('index'),
    'Create',
  );

 ?>


    <div id="ajax101" >
  <div class="form" >

    <?php $form=$this->beginWidget('UActiveForm', array(
    'id'=>'registration-form',
    'enableAjaxValidation'=>true,
    'disableAjaxValidationAttributes'=>array('RegistrationForm_verifyCode'),
    'clientOptions'=>array(
            'validateOnSubmit'=>true,
    ),
    'htmlOptions' => array('enctype'=>'multipart/form-data'),
    )); ?>

    <p class="note"><?php echo UserModule::t('Fields with <span class="required">*</span> are required.'); ?></p>

    <?php echo $form->errorSummary(array($model/*,$profile*/)); ?>

    <div class="row">
    <div class="rlabel">
    <?php echo $form->labelEx($model,'username', array("style"=>"display:inline")); ?>
    </div>
    <div class="rtextfield">
    <?php echo $form->textField($model,'username', array("style"=>"margin-left:43px")); ?>
    </div>
    <div class="rerror">
    <?php echo $form->error($model,'username', array("style"=>"margin-left:113px")); ?>
    </div>
    </div>

    <div class="row">
    <?php echo $form->labelEx($model,'password', array("style"=>"display:inline")); ?>
    <?php echo $form->passwordField($model,'password', array("style"=>"margin-left:43px")); ?>
    <?php echo $form->error($model,'password', array("style"=>"margin-left:113px")); ?>
    <p class="hint">
    <?php echo UserModule::t("Minimal password length 4 symbols."); ?>
    </p>
    </div>

    <div class="row">
    <?php echo $form->labelEx($model,'verifyPassword', array("style"=>"display:inline")); ?>
    <?php echo $form->passwordField($model,'verifyPassword'); ?>
    <?php echo $form->error($model,'verifyPassword', array("style"=>"margin-left:113px")); ?>
    </div>

    <div class="row">
    <?php echo $form->labelEx($model,'email', array("style"=>"display:inline")); ?>
    <?php echo $form->textField($model,'email', array("style"=>"margin-left:65px")); ?>
    <?php echo $form->error($model,'email', array("style"=>"margin-left:113px")); ?>
    </div>

    <div class="row">
    <?php echo $form->labelEx($model,'user_type', array("style"=>"display:inline")); ?>
    <?php echo $form->dropDownList($model,'user_type',$model->getUType()); ?>
    <?php echo $form->error($model,'user_type', array("style"=>"margin-left:113px")); ?>
    </div>


    <?php if (UserModule::doCaptcha('registration')): ?>
    <div class="row">
            <?php echo $form->labelEx($model,'verifyCode'); ?>

            <?php $this->widget('CCaptcha'); ?>
            <?php echo $form->textField($model,'verifyCode'); ?>
            <?php echo $form->error($model,'verifyCode'); ?>

            <p class="hint"><?php echo UserModule::t("Please enter the letters as they are shown in the image above."); ?>
            <br/><?php echo UserModule::t("Letters are not case-sensitive."); ?></p>
    </div>
    <?php endif; ?>

    <div class="row submit">
            <?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),array('/user/register'),array('update'=>'#ajax101')); ?>//div for form
    </div>

 <?php $this->endWidget(); ?>
     </div>
  </div><!-- form -->

   <?php endif; ?>

I think the problem exists here

   <?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),array('/user/register'),array('update'=>'form')); ?>//div for form
    </div>

example if I have 3 menu items home aboutus contact

suppose visited home when I click on register a model window with registration form appears and when i click on submit button model->save as well make another call using ajax to update that model window with thank you message

similarly with other items in menu

whats happening is it saves and redirects to /user/registration with thank you but i need same model window and not to be updated with thank message and not redirected thank message

I did try this but it did not save

   <?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),'',array('update'=>'form-content')); ?>


 I am calling ajax within ajax . 
Cœur
  • 37,241
  • 25
  • 195
  • 267
user3419342
  • 35
  • 1
  • 8

2 Answers2

0

try with

 <?php
                        echo CHtml::ajaxSubmitButton(signup , CHtml::normalizeUrl(array('<controller>/<action>', 'render' => true)), array(
                            'dataType' => 'json',
                            'type' => 'post',
                            'success' => 'function(data) {


                    }',
                        'beforeSend' => 'function(){   

                      }','complete' => 'function(){


                      }',

                                ), array('id' => 'signup', 'class' => ''));

                        ?>
Rejayi CS
  • 1,034
  • 1
  • 10
  • 22
  • not working :( again it redirects it should not redirect and must display in same model window i wanna know array('/' needed? because in the same model window i wanna render the recursive ajax call wherein the registration form renders .. i think its not submitting via ajax – user3419342 Mar 14 '14 at 11:46
0

The problem is in your controller, you have to stop Yii, return; alone won't cut it.

if ($model->save()) {
   if($this->isAjaxRequest)
   {
       ehco 'thank you for  registration';
       Yii::app()->end(); // to stop yii
   }
   else 
   {
       // probably redirect
   }
}
Developerium
  • 7,155
  • 5
  • 36
  • 56
  • sorry for the delay cexcetion Property "RegistrationController.isAjaxRequest" is not defined. is been rendered .if i use if(Yii::app()->request->isAjaxRequest) it saves but redirects to another page with no thanx message ... am not understanding whats wrong – user3419342 Mar 15 '14 at 05:48
  • why don't you use flash messages for your registration message – Developerium Mar 15 '14 at 05:57
  • i havent used flash messages have no idea are there some demos ..... can i all of following..suppose visited home when i click on register a model window with registration form appears and when i clich on submit button model->svae as wel should make another call using ajax to update that model window with thank you message save and yet be in the model window displaying the message can you please let me know any demos.... am not sure am i clear – user3419342 Mar 15 '14 at 14:04