Autofill

hi all…

can anyone tell me how to make autofill in textfield…for example, if i access page with url


http://localhost/..../artikel/23   // 23 is id artikel

the textfield on that page is filled automatically with 23

If your textfield is bound to some form, i. e. $form = new SomeFormModel then you can just assign the value to form field, like this:


public function actionCreate($id)

{

    $record = new SomeForm;

    $record->yourField = $id;

}



I use $id as action named param in this example, so change it to actual variable.

If you have no form class, then you can use CHtml for easy generation of text fields and set the required value as param.

thx ORey for your response…that’s success to fill.but i have any problem.after textfield filled automatic, i want to fill another field on the same page automatic too (in image)…

i try to make this in controller :




public function actionTrackdispo($id_naskah)

	{

		$track=new Naskah;

		$track->track=$id_naskah;

		$model=new Naskah;

		if(isset($_POST['Naskah']))

		{

			$model->attributes=$_POST['Naskah'];

			$model->lampiran=CUploadedFile::getInstance($model,'lampiran');

			 

			if($model->save())

			{

				if($file_name=$model->lampiran)

				{

					$file_name->saveAs(dirname(Yii::app()->basePath) . '/files/'.$file_name);

					$this->redirect(array('sent'));

				}else

					$this->redirect(array('sent'));

			}

		}

		if(Yii::app()->request->isAjaxRequest && $_POST['Naskah'])

		  {

		   $id = $_POST['Naskah']['track'];

		   $model = Naskah::model()->findByPk($id);

		   echo CJSON::encode($model);

		  }

		  else 

		  {

		   $model = new Naskah;

		   $this->render('trackdispo',array(

		    'model'=>$model,

			'track'=>$track,

		   ));

		  }

	}



in view :




	<table>

			<tr>

				<th>

					<div class="dispo">

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

						<?php echo $form->dropDownList($track,'track',

							CHtml::listData($model->findAll(), 'id_naskah', 'id_naskah'),

					    array('empty'=>'-Pilih ID Naskah-',

					      'ajax'=>array(

					       'type'=>'POST',

					       'beforeSend'=>'function(data){if($(this+ ":selected").val()==""){alert("Silakan Pilih");return false;}}',

					       'dataType'=>'json',

					       'success'=>'function(data){$("#Naskah_no_referensi").val(data.no);$("#Naskah_nonaskah").val(data.nonaskah);$("#Naskah_apa").val(data.apa);$("#Naskah_tgl_terima").val(data.tgl_terima);$("#Naskah_perihal").val(data.perihal);$("#Naskah_lampiran").val(data.lampiran)}',

					      ),

					    )

					   ); ?>

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

					</div>

				</th>

				<th>

					<div class="dispo">

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

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

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

					</div>

				</th>

				

				<th>

					<div class="dispo">

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

							<?php

							$this->widget('zii.widgets.jui.CJuiDatePicker', array(

							'model'=>$model,

							'attribute'=>'tgl_kirim',

							 'value'=>$model->tgl_kirim,

							 // additional javascript options for the date picker plugin

							 'options'=>array(

							 'showAnim'=>'fold',

							 'showButtonPanel'=>true,

							 'autoSize'=>true,

							 'dateFormat'=>'yy-mm-dd',

							 'defaultDate'=>$model->tgl_kirim,

							 ),

							));

							?>

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

					</div>

				</th>

				

				<th>

					<div class="dispo">

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

						<?php echo $form->dropDownList($model,'id_jenissurat',

									CHtml::listData(Jenissurat::model()->findAll(), 'id_jenissurat', 'jenis_surat'),

									array('empty'=>'-- Pilih Jenis Naskah --'));?>

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

					</div>

				</th>

			</tr>

		</table>

		<?echo '<hr/>';?>

		<table>

			<tr>

				<th>	

					

					<div class="dispo">

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

						<?php echo $form->dropDownList($model,'id_penerima',

								CHtml::listData(Jabatan::model()->findAll(), 'id_jabatan', 'jabatan'),

								array('empty'=>'-- Pilih Penerima --'));?>

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

					</div>

				</th>

				

				<th>

					<div class="dispo">

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

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

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

					</div>

					<div class="dispo">

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

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

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

					</div>

				</th>

				<th>

					<div class="dispo">

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

						<?php echo $form->textArea($model,'perihal',array('rows'=>5, 'cols'=>18)); ?>

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

					</div>

				</th>

			</tr>

		</table>



but not worked