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.
15 Posts 4072 Views
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?
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");
Or you could just do it the easy way:
new TextField("Search", "Search", $value="Some text here"),
Forgive me it's Friday!
Thanks for replying Novaweb, but I don't actually want to set the value attribute, I want to set the placeholder attribute.
Sorry Onion, not sure about SilverStripe HTML5 form compatibility in 2.4.X
See here: [url]http://www.silverstripe.org/general-questions/show/15181[/url]
Ah bugger, that's a shame. Nevermind, I'll add it with jQuery instead. Thanks!
It's possible. I've just enabled this for search on my site (using SS 2.4.4)
Its possible to set a placeholder text in 3.0 not sure for earlier versions of Silverstripe using