Can I use 2 fields for the same input?

I have the following situation:

I have Subject, Seminar, Participants and Pending.

I register participants in Seminars for a specific Subject.

If a Seminar is cancelled, the registered Participants go into Pending (so in the next Seminar of the same subject, the user will be notified about these pending Participants).

How can I display these pending participants in the registration form?

Seminar Model:


public function createPending(){


   $listParticipants=Register::model()->findAllByAttributes(array('seminarID'=>$this->seminarID));

	

		foreach ($listParticipants as $lp){

			$pending=new Pending();

			$pending->subjectID=$this->subjectID;

			$pending->participantID=$lp->participantID;

			$pending->save();

		}

	}

Registration _form:


	


	<div class="row">

		<?php echo $form->labelEx($model,'seminarID'); ?>

		<?php echo $form->textField($model,'seminarID',$model->getSeminar()); ?>

		<?php echo $form->error($model,'seminarID'); ?>

	</div>





        And here is what I want: when a seminar is selected (which is of a specific subject)

I want to show here if there is any pending participant for the same subject...

and I want to select from this list and it should store that participant ID in the registration.

How can it work at the same time when there is also the below field for selecting participants?

      




        <div class="row">

		<?php echo $form->labelEx($model,'participantID'); ?>

		<?php echo $form->dropDownList($model,'participantID',$model->getParticipant()); ?>

		<?php echo $form->error($model,'cTeilnehmerID'); ?>

	</div>



Maybe what you need are dependent dropDownLists

http://www.yiiframework.com/wiki/24/

I am already using dependent dropDownLists, but doesn’t fit properly to this requirement.

I would like to know if it is possible to have lets say 2 dropDownLists, but both of them assigning the same attribute? And not to have conflict or so with each other? Is there any way to do this?

hi

you take first drop down for seminars and by ajax send “seminar_id”, then in ajax action search in pending model where seminar_id = $_POST[‘seminar_id’]. and get participant in listData

Ok, here is the solution to my question (at least most of it, but still a problem):

Registration _form:




	<div class="row">

		<?php echo $form->labelEx($model,'seminarID'); ?>

		<?php echo $form->dropDownList($model, 'seminarID', $model->getSeminar(),

				array('ajax'=>array(

						'type'=>'POST',

						'url'=>CController::createUrl('Registration/SelectPending'),

						'update'=>'#'.CHtml::activeID($model, 'participantID'),

						'beforeSend'=>'function(){

							$("#Registration_participantID").find("option").remove();

						}'

				)	

		)); ?>

		<?php echo $form->error($model,'seminarID'); ?>

	</div>

	

	<div class="row">

		<?php echo $form->labelEx($model,'participantID'); ?>

		<?php echo $form->dropDownList($model,'participantID',Pending::model()->getParticipant()); ?>

		<?php echo $form->error($model,'participantID'); ?>

	</div>



RegistrationController:




	public function actionSelectPending(){

		$seminar=$_POST['Registration']['seminarID'];

		$test=Seminar::model()->find('seminar = :test', array(':test'=>$seminar))->subjectID;

		

		$list=Pending::model()->findAll('subjectID = :sub', array(':sub'=>$test));

<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' /> $list=CHtml::listData($list,'participantID','participantID');


	

		foreach ($list as $value=>$name){

			echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name),true);

		}

	}



But I have a problem: In the line with "question marks" everything works fine.

But I want to show the name of participant. In this case there is a problem doing:




$list=CHtml::listData($list,'participantID','participant.participantName');



where ‘participant’ is the name of relation. In this case it will show the names of participants where their ID are as the pendingID and not paricipant ID!!!

I tried anonymous function inside listData(), but still same result…

Any idea how to solve this?

you are check out firebug and console tab.

see parameters passed.

My mistake…

In Pending I had relation:




'participant' => array(self::HAS_ONE, 'Participant', 'participantID'),



It should be:




'participant' => array(self::BELONGS_TO, 'Participant', 'participantID'),