Page 1 of 1
Textbox Background Image
#1
Posted 11 January 2013 - 04:49 AM
Hi,
I am new to Yii, and I dont know how to put background image for the textbox. So please any one can help me.
Regards,
Pratik Shah
I am new to Yii, and I dont know how to put background image for the textbox. So please any one can help me.
Regards,
Pratik Shah
#3
Posted 11 January 2013 - 07:19 AM
If you're using CHtml and want to apply it inline, you can do something like this:
You're probably better off applying it in your style sheet though.
CHtml::textField($name, $value, array(
'style'=>'background-image: url("' . Yii::app()->baseUrl . '/images/image.png");',
));
You're probably better off applying it in your style sheet though.
#4
Posted 16 January 2013 - 02:51 AM
I was using
<?php echo $form->textField($model,'username'); ?>
to display the textbox instead of textbox i want image, when i used
<?php CHtml::textField($model, 'username', array('style'=>'background-image: url("' . Yii::app()->baseUrl . '/images/image.png");',));?>
I got an error saying that
Object of class LoginForm could not be converted to string
<?php echo $form->textField($model,'username'); ?>
to display the textbox instead of textbox i want image, when i used
<?php CHtml::textField($model, 'username', array('style'=>'background-image: url("' . Yii::app()->baseUrl . '/images/image.png");',));?>
I got an error saying that
Object of class LoginForm could not be converted to string
#5
Posted 16 January 2013 - 08:37 AM
It sounds like the error is coming from somewhere else in your code. Look at the stack trace and check which line causes the error.
Also, you can continue to use $form->textField(), just use the array that I suggested as its third parameter.
Also, you can continue to use $form->textField(), just use the array that I suggested as its third parameter.
#6
Posted 16 January 2013 - 09:11 AM
there is a difference between:
and
CHtml::textField($name, $value...
and
CHtml::activeTextField($model, $attribute...
red
#7
Posted 17 January 2013 - 07:01 AM
I am using the same
as you mentioned I'm using it in array but still it is giving the error attaching the snapshot of stack trace.
<?php echo CHtml::image(Yii::app()->request->baseUrl."/images/username.png");?>
<?php CHtml::textField($model, 'username', array('style'=>'background-image: url("' . Yii::app()->baseUrl . '/images/UserName-Field.png");',));?>
as you mentioned I'm using it in array but still it is giving the error attaching the snapshot of stack trace.
#8
Posted 17 January 2013 - 07:08 AM
Pratik Shah, on 17 January 2013 - 07:01 AM, said:
I am using the same
as you mentioned I'm using it in array but still it is giving the error attaching the snapshot of stack trace.
<?php echo CHtml::image(Yii::app()->request->baseUrl."/images/username.png");?>
<?php CHtml::textField($model, 'username', array('style'=>'background-image: url("' . Yii::app()->baseUrl . '/images/UserName-Field.png");',));?>
as you mentioned I'm using it in array but still it is giving the error attaching the snapshot of stack trace.
like I said - there is a difference between Keith's suggestions and how you use it. If you provide $model and attribute name you should use "active*" functions (in your case activeTextField), textField function requires field name as string and its value as string in first two arguments. This applies to CHtml helper.
Earlier you used CActiveForm widget which wraps those methods so you do not need "active" prefix:
class CActiveForm extends CWidget {
...
public function textField($model,$attribute,$htmlOptions=array())
{
return CHtml::activeTextField($model,$attribute,$htmlOptions);
}
...
}
red
#9
Posted 17 January 2013 - 07:09 AM
Thanx sir,
Now its not giving me error but image is not rendering...my Image is in the Image folder only and basepath is also correct... is there any problem with this quotes..?
Now its not giving me error but image is not rendering...my Image is in the Image folder only and basepath is also correct... is there any problem with this quotes..?
<?php CHtml::activeTextField($model, 'username', array('style'=>'background-image: url("'.Yii::app()->request->baseUrl .'/images/UserName-Field.png");',));?>
Share this topic:
Page 1 of 1

Help













