I have a div inside a form but I'm not quite sure how to retrieve the chosen value into the controller:
<?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'system-users-form', 'enableAjaxValidation'=>false, )); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <button id="abutton">Already a Supplier</button> <br> <div class="row" id="toshow" style="display:none" name="suppliers"> <?php $supplier = SupplierHead::model()->findAll(); $list = CHtml::listData($supplier ,'head_id','head_name'); echo $form->DropDownList($model,'party_id', $list, array('prompt'=>'Select Supplier')); ?> </div> <script> $(document).ready(function() { $("#abutton").click(function(e){ e.preventDefault(); $("#toshow").css('display', 'block'); }); }); </script> <div class="row"> <?php echo $form->labelEx($model,'username'); ?> <?php echo $form->textField($model,'username',array('size'=>60,'maxlength'=>200)); ?> <?php echo $form->error($model,'username'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'password'); ?> <?php echo $form->passwordField($model,'password',array('size'=>60,'maxlength'=>255)); ?> <?php echo $form->error($model,'password'); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?> </div> <?php $this->endWidget(); ?> </div><!-- form --> Note that this row also belongs to another model. How would I retrieve this inside another controller?
Controller Code:
public function actionCreate() { $model = new SystemUsers; $modelParties = new Parties; $modelPersons = new Persons; $supplierHead = new SupplierHead; // $modelPR = new PartyRoles; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($invoice); if (isset($_POST['SystemUsers'])) { $model->attributes = $_POST['SystemUsers']; Yii::app()->db->createCommand("insert into parties (party_type_id) values ('1')")->execute(); $id = Yii::app()->db->lastInsertId; $_POST["SupplierHead"]["party_id"]; $model->password = md5($model->password); $model->party_id = $id; $model->status = "Approved"; $model->date_modified = new CDbExpression('NOW()'); $email = $model->username; if($company != null) { Yii::app()->db->createCommand("insert into persons (party_id,email,company_name) values ('".$id."','".$email."','".$company."')")->execute(); } Yii::app()->db->createCommand("insert into persons (party_id,email) values ('".$id."','".$email."')")->execute(); Yii::app()->db->createCommand("insert into party_roles(party_id,role_id) values ('".$id."','2')")->execute(); /* $valid = true; $valid &= $model->validate(); $valid &= $modelParties->validate(); if($valid) { $modelParties->save(); $model->party_id = $modelParties->getPrimaryKey(); */ if($model->save()) echo ("<SCRIPT LANGUAGE='JavaScript'> window.alert('User Created') window.location.href='create'; </SCRIPT>"); // } else $this->redirect(array('views22','id'=>$model->id)); } $this->render('create',array( 'parties'=>$modelParties, 'model'=>$model, )); }
Model for SystemUsers:
public function tableName() { return 'system_users'; } /** * @return array validation rules for model attributes. */ public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( array('username, password', 'required'), array('isLogin', 'numerical', 'integerOnly'=>true), array('date_modified','default', 'value'=>new CDbExpression('NOW()'), ), array('date_last_login','default', 'value'=>new CDbExpression('NOW()'), ), array('date_created','default', 'value'=>new CDbExpression('NOW()'), ), array('status','default','value'=>'Approved'), array('user_role','default','value'=>'MEMBER'), array('isLogin','default','value'=>'1'), array('username', 'length', 'max'=>200), array('password', 'length', 'max'=>255), // The following rule is used by search(). // Please remove those attributes that should not be searched. ); } EDIT
I added my model and the rest of the form to show you the confusion. The dropdown list div is value i'm trying to input into a different model and it does not exist as an attribute for system_users so It's not going through the POST.