Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How do I put initial text in the search box?

edited August 2011 in Vanilla 2.0 - 2.8
I am adapting a theme and I want to put some initial text in the search box - something like "Search this forum". If I was writing an HTML form, I would just include value="Search this forum" and that should work.

But when I look at the default.master.php file, the form code is written in php, and I don't know how to do the equivalent of the value statement. I would have thought the code: $Form->TextBox('Search'), would have been the place, but it seems not.

Can anyone help this php-challenged Vanilla user do this please? Thanks.

Best Answer


  • Options
    Does anyone have an answer here please?
  • Options
    They probably do, but not within 1 or 2 days. Give it some time. Try to think logically and you might find the answer yourself.

    There was an error rendering this rich post.

  • Options
    I'd be interested in this one too. I attempted to read library/core/class.form.php but it wasn't entirely clear to me. Relevant section:
       * Returns XHTML for a button.
    * @param string $ButtonCode The translation code for the text on the button.
    * @param array $Attributes An associative array of attributes for the button. Here is a list of
    * "special" attributes and their default values:
    * Attribute Options Default
    * ------------------------------------------------------------------------
    * Type The type of submit button 'submit'
    * Value Ignored for $ButtonCode $ButtonCode translated
    * @return string
    public function Button($ButtonCode, $Attributes = FALSE) {
    $Type = ArrayValueI('type', $Attributes);
    if ($Type === FALSE) $Type = 'submit';

    $CssClass = ArrayValueI('class', $Attributes);
    if ($CssClass === FALSE) $Attributes['class'] = 'Button';

    $Return = '_IDAttribute($ButtonCode, $Attributes);
    $Return .= $this->_NameAttribute($ButtonCode, $Attributes);
    $Return .= ' value="' . T($ButtonCode, ArrayValue('value', $Attributes)) . '"';
    $Return .= $this->_AttributesToString($Attributes);
    $Return .= " />\n";
    return $Return;
  • Options
    ntuyelikntuyelik New
    edited August 2011
    add following code into search box codes which are in default.master.php ;

    type="text" value="search for sth..."
  • Options
    Thanks for reply, ntuyelik. Sorry I couldn't respond sooner but i was locked out for a few days by some glitch.

    I'm sorry, but I can't see how to do this - everything I tried didn't work. I presume this is the section of code in default.master.php:

    $Form = Gdn::Factory('Form');
    $Form->InputPrefix = '';
    $Form->Open(array('action' => Url('/search'), 'method' => 'get')),
    $Form->Button('Go', array('Name' => '')),

    And I also presume the place where this code would go would be $Form->TextBox('Search'), but I can't make anything there work. Can you please help a struggling old man?
  • Options
    edited August 2011 Answer ✓

    This could probably be done rather easily with javascript, though I am still learning myself, though, it so I can't give you an example of code.

    Here is something you may find interesting, though; a jquery plugin for form defaults.
  • Options
    Yes, thanks, that does exactly what I want. Maybe I should try it. But I'm not sure I want to learn enough about jQuery to do this if there is indeed a php way to do it - and surely there is!?
Sign In or Register to comment.