title: Setting default values and Creating into Database using Yii
body: <p>I'm trying to create a new user but I'm having trouble trying to create the user because some of the values that are needed to create a user must be default values that I'm not quite sure how to set. I also need to input into a different table while the actual "create" happens from a different controller.</p>
  
  <p>Here is my form code:</p>
  
  <pre><code>&lt;?php
   /* @var $this SystemUserController */
   /* @var $model SystemUser */
   /* @var $form CActiveForm */
  ?&gt;
  
  &lt;div class="form"&gt;
  
  &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
      'id'=&gt;'system-user-form',
      'enableAjaxValidation'=&gt;false,
       )); ?&gt;
  
  &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  
  &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
  
  &lt;!--
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'party_id'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'party_id',array('size'=&gt;20,'maxlength'=&gt;20)); ?&gt;
      &lt;?php echo $form-&gt;error($model,'party_id'); ?&gt;
  &lt;/div&gt;
  !--&gt;
  &lt;div class="row" id="toshow" style="display:none" name="suppliers"&gt; &lt;?php $supplier      = SupplierHead::model()-&gt;findAll();
     $list = CHtml::listData($supplier ,'head_id','head_name'); 
     echo $form-&gt;DropDownList($model,'party_id', 
     $list, array('prompt'=&gt;'Select Supplier'));  ?&gt; 
  &lt;/div&gt;
  
  &lt;button id="abutton"&gt;Already a Supplier&lt;/button&gt;
  
  &lt;script&gt;
  $(document).ready(function() {
     $("#abutton").click(function(e){
        e.preventDefault();
        $("#toshow").css('display', 'block');
     });
  });
  &lt;/script&gt;
  
  
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'username'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'username',array('size'=&gt;60,'maxlength'=&gt;200)); ?&gt;
      &lt;?php echo $form-&gt;error($model,'username'); ?&gt;
  &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'password'); ?&gt;
      &lt;?php echo $form-&gt;passwordField($model,'password',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt;
      &lt;?php echo $form-&gt;error($model,'password'); ?&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
      $("#supplier").click(function () {
      $("#suppliers").show("slow");
      }); 
  
  &lt;/script&gt;
  &lt;!--
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'date_last_login'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'date_last_login'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'date_last_login'); ?&gt;
  &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'status'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'status',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;
      &lt;?php echo $form-&gt;error($model,'status'); ?&gt;
  &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'date_created'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'date_created'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'date_created'); ?&gt;
  &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'date_modified'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'date_modified'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'date_modified'); ?&gt;
  &lt;/div&gt;
   --!&gt;
  
  
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'user_role'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'user_role',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt;
      &lt;?php echo $form-&gt;error($model,'user_role'); ?&gt;
  &lt;/div&gt;
  
  &lt;!--
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'isLogin'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'isLogin'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'isLogin'); ?&gt;
  &lt;/div&gt;
  --!&gt;
  &lt;div class="row buttons"&gt;
      &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;
  &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  
  &lt;/div&gt;&lt;!-- form --&gt;
  </code></pre>
  
  <p>As you can see, I've commented out the attributes that I don't want to use. I also fixed the SystemUser model attributes rules() to define which attributes won't be needed for user input here:</p>
  
  <pre><code>    public function rules()
  {
      // NOTE: you should only define rules for those attributes that
      // will receive user inputs. 
      return array(
          array('party_id, username, password', 'required'),
          //array('isLogin', 'numerical', 'integerOnly'=&gt;true),
          array('party_id', 'length', 'max'=&gt;20),
          array('username', 'length', 'max'=&gt;200),
          array('password, user_role', 'length', 'max'=&gt;255),
  
          // The following rule is used by search().
          // Please remove those attributes that should not be searched.
          array('party_id, username' 'on'=&gt;'search'),
      );
  }
  </code></pre>
  
  <p>Finally, there's also a drop down list I included above from the form that is required to be inserted into a model of a different controller. How do I go about this?</p>
  
  <p>The attributes that need default values are as follows:</p>
  
  <pre><code>date_last_login
  status
  date_created
  date_modified
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've uploaded a picture of what happens when I select "Create"</p>
  
  <p><img src="https://i.stack.imgur.com/1B9Ij.png" alt="enter image description here"></p>
  
  <p>I decided not to add defaults try keeping them NULL just to see if the rules() would work. I </p>
  
  <p>Any help?</p>