Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:50:06+00:00 2026-06-17T16:50:06+00:00

I have a CActiveForm which when submitted should make a second CActiveForm become visible.

  • 0

I have a CActiveForm which when submitted should make a second CActiveForm become visible. I know how to change the htmlOptions of the form when its created but not how to access it via the controller.

My View with two forms. The second form has visibility:hidden

<div class="form">
            <?php
            $numberForm = $this->beginWidget('CActiveForm', array(
                'id' => 'addnumber-form',
                'enableAjaxValidation' => true,
                'clientOptions' => array(
                    'validateOnSubmit' => true,
                ),
                    ));
            ?>

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

            <div class="row">
                <?php echo $numberForm->labelEx($numberModel, 'number'); ?>
                <?php echo $numberForm->textField($numberModel, 'number'); ?>
                <?php echo $numberForm->error($numberModel, 'number'); ?>

                <?php
                echo CHtml::submitButton(UserModule::t("Verify"), array(
                    "class" => "btn btn-success"
                ));
                ?>

            </div>

            <?php $this->endWidget(); ?>

            <?php
            $verifyForm = $this->beginWidget('CActiveForm', array(
                    'id' => 'verify-form',
                    'enableAjaxValidation' => true,
                    'clientOptions' => array(
                        'validateOnSubmit' => true,
                    ),
                    'htmlOptions' => array("style"=>"visibility: hidden"),
                ));
            ?>

            <?php echo $verifyForm->errorSummary($verifyModel); ?>

            <p>A authorisation code has been sent to your phone. Please enter it below. If you don't receive a text message make sure you entered your number correctly and try again</p>

            <div class="row">
                <?php echo $verifyForm->labelEx($verifyModel, 'authcodeUser'); ?>
                <?php echo $verifyForm->textField($verifyModel, 'authcodeUser'); ?>
                <?php echo $verifyForm->error($verifyModel, 'authcodeUser'); ?>

                <?php
                echo CHtml::submitButton(UserModule::t("Confirm"), array(
                    "class" => "btn btn-success"
                ));
                ?>

                <?php
                    foreach(Yii::app()->user->getFlashes() as $key => $message) {
                        echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
                    }
                ?>

            </div>

            <?php $this->endWidget(); ?>


        </div><!-- form --> 

My controller for these forms

public function actionAddnumber(){
    $numberModel = new UserAddNumber;
    $verifyModel = new UserVerifyNumber;
    if (Yii::app()->user->id) {

        // ajax validator
        if(isset($_POST['ajax']) && $_POST['ajax']==='addnumber-form')
        {
            echo UActiveForm::validate($numberModel);
            Yii::app()->end();
        }

        if(isset($_POST['UserAddNumber'])) {
                $numberModel->attributes=$_POST['UserAddNumber'];
                if($numberModel->validate()) {
                    $profile = Profile::model()->findByAttributes(array('user_id'=>Yii::app()->user->id));
                    $profile->mobileNo = $numberModel->number;
                    $profile->save();

                    //MAKE $verifyForm visibility to visible uring htmlOptions

                    Yii::app()->session['authcode'] = '4444';
                }
        }

        if(isset($_POST['UserVerifyNumber'])) {
                $verifyModel->attributes=$_POST['UserVerifyNumber'];
                if($verifyModel->validate()) {
                    $profile = Profile::model()->findByAttributes(array('user_id'=>Yii::app()->user->id));
                    $profile->mobileNoVerified = True;
                    $profile->save();
                    Yii::app()->user->setFlash('profileMessage',UserModule::t("Your mobile number has been verified"));
                    $this->redirect(array("profile"));

                }
        }

    }
    $this->render('addnumber', array('numberModel'=>$numberModel, 'verifyModel' => $verifyModel));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:50:06+00:00Added an answer on June 17, 2026 at 4:50 pm

    It looks like you could just create a new variable for whether or not to show the second form and then pass it to the view. Here is your controller:

    public function actionAddnumber(){
        $numberModel = new UserAddNumber;
        $verifyModel = new UserVerifyNumber;
        $formVisibility = "hidden";
    
        if (Yii::app()->user->id) {
    
            // ajax validator
            if(isset($_POST['ajax']) && $_POST['ajax']==='addnumber-form')
            {
                echo UActiveForm::validate($numberModel);
                Yii::app()->end();
            }
    
            if(isset($_POST['UserAddNumber'])) {
                    $numberModel->attributes=$_POST['UserAddNumber'];
                    if($numberModel->validate()) {
                        $profile = Profile::model()->findByAttributes(array('user_id'=>Yii::app()->user->id));
                        $profile->mobileNo = $numberModel->number;
                        $profile->save();
    
                        //MAKE $verifyForm visibility to visible uring htmlOptions
                        $formVisibility = "visible";
    
    
                        Yii::app()->session['authcode'] = '4444';
                    }
            }
    
            if(isset($_POST['UserVerifyNumber'])) {
                    $verifyModel->attributes=$_POST['UserVerifyNumber'];
                    if($verifyModel->validate()) {
                        $profile = Profile::model()->findByAttributes(array('user_id'=>Yii::app()->user->id));
                        $profile->mobileNoVerified = True;
                        $profile->save();
                        Yii::app()->user->setFlash('profileMessage',UserModule::t("Your mobile number has been verified"));
                        $this->redirect(array("profile"));
    
                    }
            }
    
        }
        $this->render('addnumber', array('numberModel'=>$numberModel, 'verifyModel' => $verifyModel, 'formVisibility' => $formVisibility));
    }
    

    And here is the first part of your second form:

    <?php
                $verifyForm = $this->beginWidget('CActiveForm', array(
                        'id' => 'verify-form',
                        'enableAjaxValidation' => true,
                        'clientOptions' => array(
                            'validateOnSubmit' => true,
                        ),
                        'htmlOptions' => array("style"=>"visibility: ".$formVisibility),
                    ));
                ?>
    

    [edit] To make sure I am answering your question, I should add that I’ve never seen any way of changing the htmlOptions from the controller directly. That’s why I proposed this solution instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form created with CActiveForm and the HTML output is something like
I have the following form which is being used to create new records <?php
I have two forms. I need to open a second form with a button.
I have a very strange problem. I have a login form in Yii which
I try to make an app which manages client's contacts. The form is very
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
Hi. I have a problem with form-validation in Yii framework. Here is my VIEW
Have a form here with bunch of input text fields and a file upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.