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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:52:01+00:00 2026-06-15T03:52:01+00:00

I have this form (I used crud generator and model generator): Create Pig [Name]

  • 0

I have this form (I used crud generator and model generator):

Create Pig

[Name]

[Breed]

[Sickness] [Add sickness]

How do I make add sickness create a new textfield everytime I click it? I already have a table for the multivalued sicknessid, I just need to access that table and add all the sicknesses, use one same id so I can use it as foreign key in the table.

<?php
/* @var $this PigController */  
/* @var $model Pig */
/* @var $form CActiveForm */
?>
<div class="form">      
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'pig-form',
    'enableAjaxValidation'=>true,
)); ?>

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

    <?php echo $form->errorSummary($model); ?>

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

    <div class="row">
        <?php echo $form->labelEx($model,'breed'); ?>
        <?php echo $form->dropDownList($model,'breed', $model-  >getBreedOptions()); ?>
        <?php echo $form->error($model,'breed'); ?>
    </div>

    /*
    ENTER CODE FOR SICKNESS HERE
    */
    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>     
    </div>

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

</div><!-- form -->
  • 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-15T03:52:02+00:00Added an answer on June 15, 2026 at 3:52 am

    I also had the same scenario. What i have done is with script.
    Try this. It worked for me. Please do make necessary changes

      $(function(){        
          $("#add").click(function(){
    
            if(5 > $(".attr").length) {
                var cycleBlock = '<tr id="item'+i+'">';
                cycleBlock += '<td style="width: 447px;"> <label for="CategoryMstExt_Attribute">Attribute</label> <input type="text" id="CategoryMstExt_0_attributes" name="CategoryMstExt['+i+'][attributes]" class="attrName'+i+'" maxlength="100" size="44"> </td> <td> <label for="CategoryMstExt_Data_Type">Data Type</label> <select id="CategoryMstExt_'+i+'_datatype" name="CategoryMstExt['+i+'][datatype]" class="attr" onchange="javascript:checkSelection(this.value,'+i+')"> <option value="17">Textarea</option> <option value="16">Textbox</option> <option value="18">Listbox</option> </select><img  onclick="deleteElm(item'+i+'.id);" src="<?php echo Yii::app()->request->baseUrl; ?>/assets/81ff99cf/gridview/delete.png" alt=""> </td>';
                cycleBlock += '</tr>';
                var $cycleBlock = $(cycleBlock);
                $('#fields').append($cycleBlock);
                i++;
            } else {
    
                alert('Maximum attributes limit reached');
            }
        });
    });
    
    
    
    <?php 
    
        <img style="margin-left:600px;" id="add" src="<?php echo Yii::app()->request->baseUrl; ?>/media/images/add.png">
                        <table id="fields" >
                            <tr id="item1" >
                                <td style="width: 447px;"> 
                                    <?php echo $form->labelEx($model, 'Attribute'); ?>
                                    <?php echo $form->textField($model, '[0]attributes', array('size' => 44, 'maxlength' => 100, 'class' => 'attrName0')); ?>
                                </td>
                                <td > 
                                    <?php echo $form->labelEx($model, 'Data Type'); ?>                                 
                                    <?php echo $form->dropDownList($model, '[0]datatype', Array('17' => 'Textarea', '16' => 'Textbox', '18' => 'Listbox'), array('onChange' => 'javascript:checkSelection(this.value,0)', 'class' => 'attr')); ?>
                                    <img  onclick="deleteElm(item1.id);" src="<?php echo Yii::app()->request->baseUrl; ?>/media/images/delete_2.png" alt="">
                                </td>
                            </tr>
                        </table>  
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my c# application i have this small form which is used to set
I have written a login form, in this I have used, form and method
I have this form: <tbody> <tr> <th>ID</th> <th>Name</th> <th>Birthdate</th> <th><input type=text autofocus=autofocus name=textinput1/></th> <th><input
I have this form with a date input. echo $this->Form->create('Nodata'); echo $this->Form->input('date1', array('type' =>
I have a ad banner that has a form and this is used by
I used nifty scaffolding for create controller 'A'. For this controller I have in
I have a PartialView that is a form used to create or modify a
I have built a nested resources between question and answer model. This is form
I have a form that lets users create new records, In the field that
I have this database field that used as the form input value '. $variety['price'].

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.