Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[solved] Add placeholder text into search box


Go to End


15 Posts   10669 Views

Avatar
onion

Community Member, 10 Posts

1 March 2012 at 5:53am

Hi, I've created a search box using the tutorial and it works fine. I want to add some placeholder text though that says something like "enter your text here to search". Usually you add this as a placeholder="" attribute to the input element (it's a new HTML5 attribute for input fields).
How and where would I add this addribute to the input element?

Thanks!

Avatar
novaweb

Community Member, 116 Posts

2 March 2012 at 2:34pm

Hi Onion,

In your form function, do the following:

$mySearchField = new TextField("Search") // You'll need to define it as a variable, as I have done... not just begin the line with "new TextField"

Then under your $actions FieldSet, write:
$mySearchField->setValue("My Placeholder Text");

Good Luck,

Josh

Avatar
novaweb

Community Member, 116 Posts

2 March 2012 at 2:37pm

Or you could just do it the easy way:


new TextField("Search", "Search", $value="Some text here"),

Forgive me it's Friday!

Avatar
onion

Community Member, 10 Posts

2 March 2012 at 10:44pm

Thanks for replying Novaweb, but I don't actually want to set the value attribute, I want to set the placeholder attribute.

http://www.w3schools.com/html5/att_input_placeholder.asp

Avatar
novaweb

Community Member, 116 Posts

5 March 2012 at 9:13am

Sorry Onion, not sure about SilverStripe HTML5 form compatibility in 2.4.X

See here: http://www.silverstripe.org/general-questions/show/15181

Avatar
onion

Community Member, 10 Posts

5 March 2012 at 10:23pm

Ah bugger, that's a shame. Nevermind, I'll add it with jQuery instead. Thanks!

Avatar
Corry

Community Member, 17 Posts

16 March 2012 at 12:14am

It's possible. I've just enabled this for search on my site (using SS 2.4.4)

See http://www.silverstripe.org/all-other-modules/show/18347

Avatar
mdowton

Community Member, 2 Posts

12 September 2013 at 1:47pm

Its possible to set a placeholder text in 3.0 not sure for earlier versions of Silverstripe using
$field->setAttribute('placeholder', 'value');

Go to Top