kiran123
(Sharmakiran71)
May 29, 2012, 10:43am
1
Hi,
I had prepare query which fetch data from different table and pass to form using controller, but i can’t get idea that how i can show this data in text field or dropdown with validation.
Below code can give you idea what i want,
<?php print_r($pdata); ?> // got data as array
<?php echo $form->errorSummary($model); ?>
<?php echo CHtml::activeTextField($model, "first_name"); ?>
<div class="row">
<?php echo $form->labelEx($model,'first_name'); ?>
<?php echo $form->textField($model,'first_name',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'first_name'); ?>
</div>
but i want to pass array data in custom fields as pass above from model…
<?php echo $form->dropDownList($model,'nationality_id',CHtml::listData(Countries::model()->findAll(),'id','name')); ?>
<?php echo CHtml::activeTextField($model, "first_name",,array('value'=> '-value here-' )); ?>
is this u need?
kiran123
(Sharmakiran71)
May 29, 2012, 11:01am
3
no, i had update form as normal form in view folder.
now i want to add other fields as i fetch that with different join table.
here the scenario is in form i had fields passing with $model, but i want extra fields with my array value in it and also want validation as admin can’t update field with blank data…
no, i had update form as normal form in view folder.
now i want to add other fields as i fetch that with different join table.
here the scenario is in form i had fields passing with $model, but i want extra fields with my array value in it and also want validation as admin can’t update field with blank data…
with out model?
<?php echo CHtml::activeTextField(“first_name”,’’,array(‘value’=> ‘-value here-’ )); ?>
kiran123
(Sharmakiran71)
May 29, 2012, 11:15am
5
In this i had to pass like,
<?php echo CHtml::activeTextField($model, 'attribute_name', array('name'=>'field_one')); ?>
but i want to pass my array variable showing value in textbox.
and main thing is validation as admin can’t update with blank field.
Balu
(Mbalu123)
May 29, 2012, 11:28am
6
In this i had to pass like,
<?php echo CHtml::activeTextField($model, 'attribute_name', array('name'=>'field_one')); ?>
but i want to pass my array variable showing value in textbox.
and main thing is validation as admin can’t update with blank field.
Do you want each values in your array in separate text box?
kiran123
(Sharmakiran71)
May 29, 2012, 11:31am
7
Yes, i want is simple thing.
I fetch data by join query from different table and now i want to update that data using update(_form) form.
which contain textbox with that array data and then i want to edit(update) that data.
other thing is this must be validate like crud functionality as no data will left blank by admin.
to show the array value in textfield just use - array(‘value’=> ‘-value here-’ )…
kiran123
(Sharmakiran71)
May 29, 2012, 12:29pm
9
i use as,
<?php echo CHtml::activeTextField($model, 'test', array('value'=>$pdata[0]['last_name'])); ?>
here i mark textfield as ‘test’ and it will give value in controller as provided, that is fine.
but how can i validate the field. i don’t want field to post blank.
i use as,
<?php echo CHtml::activeTextField($model, 'test', array('value'=>$pdata[0]['last_name'])); ?>
here i mark textfield as ‘test’ and it will give value in controller as provided, that is fine.
but how can i validate the field. i don’t want field to post blank.
simply include ‘test’ in rules as required in the model…
kiran123
(Sharmakiran71)
May 29, 2012, 12:38pm
11
Ok. thank you all for your reply.
now i got the flow what have to do.
as Rajith say… for custom text field i use following code,
<?php echo CHtml::activeTextField($model, 'test', array('value'=>$pdata[0]['last_name'])); ?>
so, now i got post value as ‘test’.
and for validate it i add ‘test’ ( name of text field ) in model for validation.