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 8755445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:51:42+00:00 2026-06-13T13:51:42+00:00

I am developing a registration form in YII. In my form there is a

  • 0

I am developing a registration form in YII. In my form there is a radio option to choose register as Mode1 or register as Mode2. If user chooses mode1, data’s should be entered to table1 or it should entered to table2.
In YII each model deals with one table. Here my form deals with two tables.

So how to handle such a form to validate and enter data’s to table in YII?

  • 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-13T13:51:43+00:00Added an answer on June 13, 2026 at 1:51 pm

    The easiest way is to create one model for the form (assuming they have the same fields?)
    This class would extend CFormModel (in the example below I refer to this model as GlobalFormModel)

    This model would have the same attributes as the other two models, as well as one new attribute called mode
    When the form is submitted, in the controller you can handle it based on which mode and validate it against the correct model, eg:

    $model = new GlobalFormModel
    
    if(isset($_POST['GlobalFormModel'])){
        $model->attributes = $_POST['GlobalFormModel']; 
    
        if ($model->mode == 1){
            $newmodel = new FormOne;
            $newmodel->attributes = $model->attributes;
        } else {
             $newmodel = new FormTwo;
             $newmodel->attributes = $model->attributes;
        } 
    
        ... // validate and save $newmodel
    }
    
    $this->render("yourview",array("model"=>$model));
    

    Where FormOne is the model associated with the first table, and FormTwo is associated with the second table. First you create a new instance of the GlobalFormModel (which is passed to the view). You check if the form has been submitted (you could validate it here or after loading one of the two models, that is your choice). You check the mode, and then load the correct model.

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

Sidebar

Related Questions

I am developing a student registration form in asp.net. there are two tables viz
Currently I'm developing a registration form for new user in Android (native app.) and
I am developing a course registration website. A user can enroll in a class,
I am developing a registration form with field validation. So, can someone provide me
I am developing a social networking site. It has functionality like user registration, people
Am developing one website for which I have to do user login and registration
I am developing an application where user can register themselves by filling up the
I am developing an Android application associated with a website. There is a registration
I am a newbie to zend framework. I am developing a simple user registration
I'm developing a registration website and there's a part where I need to add

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.