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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:11:43+00:00 2026-06-12T05:11:43+00:00

I have created two models :User and UserProfile , Now I want display in

  • 0

I have created two models :User and UserProfile , Now I want display in some fields of UserProfile in User view (_form) , on create action in user table I have done this :

  public function actionCreate() {



    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    $user_form= new TblUser;
    $profile_form = new TblUserProfile;

            if(isset($_POST['user_form'], $_POST['profile_form'])){



     // populate input data to $a and $b
    $user_form->attributes=$_POST['user_form'];
    $profile_form->attributes=$_POST['profile_form'];


           // validate BOTH $a and $b
          $valid=$user_form->validate();
         $valid=$profile_form->validate() && $valid;



        if($valid)
    {
        // use false parameter to disable validation
        $user_form->save(false);


         $profile_form->save(false);
            // ...redirect to another page


        }
    }

    $this->render('create', array(
        'user_form'=>$user_form,
        'profile_form'=>$profile_form,
    ));

}

Then ,

This is my _form class of user table

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo Chtml::errorSummary($user_form,$profile_form); ?>

    <div class="row">
        <?php //echo $form->labelEx($model,'id'); ?>
        <?php echo $form->hiddenField($user_form,'id'); ?> 
        <?php //echo $form->error($model,'id'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($user_form,'password'); ?>
        <?php echo $form->passwordField($user_form,'password',array('size'=>40,'maxlength'=>40)); ?>
        <?php echo $form->error($user_form,'password'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($user_form,'username'); ?>
        <?php echo $form->textField($user_form,'username',array('size'=>45,'maxlength'=>45)); ?>
        <?php // echo $form->error($user_form,'username'); ?>
    </div>

            <div class="row">
        <?php //echo $form->labelEx($model,'Is_active'); ?>
        <?php echo $form->HiddenField($user_form,'Is_active'); ?>
        <?php //echo $form->error($model,'Is_active'); ?>
    </div>


        <div class="row">
        <?php echo $form->labelEx($profile_form,'user_first_name '); ?>
        <?php echo $form->textField($profile_form,'user_first_name ',array('size'=>45,'maxlength'=>45)); ?>
        <?php  echo $form->error($profile_form,'user_first_name '); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton($user_form->isNewRecord ? 'Create' : 'Save'); ?>
    </div>
<?php echo CHtml::endForm(); ?>


        <!-- form -->

Now , I have render both models in same view like this ,

<?php echo $this->renderPartial('_form', 
    array('user_form'=>$user_form,'profile_form'=>$profile_form)); ?>

Problem which I am facing after doing all this is :

 Undefined variable: form

C:\wamp\www\topicoll\protected\views\tblUser\_form.php(9)

01 
02 
03 <?php echo CHtml::beginForm(); ?>
04 
05 
06 
07     <p class="note">Fields with <span class="required">*</span> are required.</p>
08 
09     <?php echo CHtml::errorSummary($user_form,$profile_form); ?>
10 
11     <div class="row">
12         <?php //echo $form->labelEx($model,'id'); ?>
13         <?php echo $form->hiddenField($user_form,'id'); ?> 
14         <?php //echo $form->error($model,'id'); ?>
15     </div>
16 
17     <div class="row">
18         <?php echo $form->labelEx($user_form,'password'); ?>
19         <?php echo $form->passwordField($user_form,'password',array('size'=>40,'maxlength'=>40)); ?>
20         <?php echo $form->error($user_form,'password'); ?>
21     </div>

Please tell me what I am missing !

  • 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-12T05:11:45+00:00Added an answer on June 12, 2026 at 5:11 am

    oh.. you are using CHtml to start a form CHtml::beginForm() and to end CHtml::endForm()

    if you do so, you have to use CHtml to generate form elements as well i.e. CHtml::activeTextfield($model, 'field', array()) and CHtml::activeLabelEx($model, 'field') in all all places in your _form

    other way is…

    add this code instead of CHtml::beginForm().

    $form=$this->beginWidget('CActiveForm', array(
        'id'=>'user-form',
        'enableAjaxValidation'=>false,
        'clientOptions'=>array(
        ),
    ));
    

    and add this code in place of CHtml::endForm()

    $this->endWidget();
    

    it will fix your problem.

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

Sidebar

Related Questions

I have two models: UserProfile (extended from user) and Cv . I created another
I have the following two models: class Position(models.Model): position = models.CharField(max_length=100) class UserProfile(models.Model): user
I have two models jobs and clients . A user can simple create a
I have two models user and profile. I want to save the username and
I have two models in Django: User (pre-defined by Django) and UserProfile. The two
I have two models: Person and Address which I'd like to create in a
I have created two WindowSurface (WPF), and I want to navigate betwen them. I've
I have two models, User and Account. Each user may have one account. Creating
For Django 1.1. I have this in my models.py: class User(models.Model): created = models.DateTimeField(auto_now_add=True)
I have two apps, account and myapp. I'm trying to display in a view

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.