Yii Framework Forum: Textbox Background Image - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Textbox Background Image Rate Topic: -----

#1 User is offline   Pratik Shah 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 21-November 12
  • Location:Ahmedabad

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
0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 677
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 11 January 2013 - 06:49 AM

what textbox some code would help perhaps
0

#3 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 11 January 2013 - 07:19 AM

If you're using CHtml and want to apply it inline, you can do something like this:

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.
0

#4 User is offline   Pratik Shah 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 21-November 12
  • Location:Ahmedabad

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
0

#5 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

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.
0

#6 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 771
  • Joined: 02-July 10
  • Location:Central Poland

Posted 16 January 2013 - 09:11 AM

there is a difference between:
CHtml::textField($name, $value...

and
CHtml::activeTextField($model, $attribute...

red
0

#7 User is offline   Pratik Shah 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 21-November 12
  • Location:Ahmedabad

Posted 17 January 2013 - 07:01 AM

I am using the same


<?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.
0

#8 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 771
  • Joined: 02-July 10
  • Location:Central Poland

Posted 17 January 2013 - 07:08 AM

View PostPratik Shah, on 17 January 2013 - 07:01 AM, said:

I am using the same


<?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
0

#9 User is offline   Pratik Shah 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 21-November 12
  • Location:Ahmedabad

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..?

<?php CHtml::activeTextField($model, 'username', array('style'=>'background-image: url("'.Yii::app()->request->baseUrl .'/images/UserName-Field.png");',));?>


0

#10 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 17 January 2013 - 07:23 AM

You have to echo.
0

#11 User is offline   Pratik Shah 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 21-November 12
  • Location:Ahmedabad

Posted 17 January 2013 - 07:25 AM

View Postsoftark, on 17 January 2013 - 07:23 AM, said:

You have to echo.

oooops...its showing now...can we remove Texbox's border...?

Thanx..:)
0

#12 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 17 January 2013 - 08:54 AM

I tried googling for you. :)
http://stackoverflow...ut-boxes-chrome
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users