0

I want to change the appearance of the Drupal 7 search form. I used this code in my preprocess-html.inc file for my Omega subtheme. It didn't work. How do I assign html classes to divs within the Drupal 7 preprocess-html.inc file?

Here's what I put in that didn't work:

<html>
<body>
<?php

function mythemename_form_search_block_form_alter(&$variables) {
  // custom functionality here 

}

?>
    <div class="row">
        <div class="col-md-3">
            <div class="input-group">
            <input type="text" class="form-control" placeholder="Search for...">
            <span class="input-group-btn">
            <button class="btn btn-default" type="button">Go!</button>
            </span>
            </div>
        </div>
    </div>

</body>
</html>

To clarify, how do I add this bootstrap html code to the template file? I need to add these classes to the search form.

  • To clarify, how do I add this bootstrap html code to the template file? I need to add these classes to the search form. – user55305 Dec 14 '15 at 15:10
2

To design the search block form you can override the existing search-block-form.tpl.php in the theme's template folder.

<?php

$variables['form']['search_block_form']['#attributes']['placeholder'] = "Search for...";
$variables['form']['search_block_form']['#attributes']['class'] = "form-control";

?>

<div class="row">
  <div class="col-md-3">
    <div class="input-group">      
      <span class="input-group-btn">
        <?php if (empty($variables['form']['#block']->subject)): ?>
          <button class="btn btn-default" type="button"><?php print t('Go!');?></button>
        <?php endif; ?>
        <?php print $search_form; ?>
      </span>
    </div>
  </div>
</div>
  • I keep getting a syntax error. I put <html> and <body> tags around the whole thing as before, and put your code inside the function, replacing what I had. What am i doing wrong? Thanks for your help, too :) – user55305 Dec 14 '15 at 15:13
  • Don't add <html> and <body> tag. Directly add the code and proper open and close the php tag. On which line you get the error ? – Pallavi Sugandhi Dec 15 '15 at 8:50
  • I get the error on the line of the first <div>. The error was on <div class="row">, and then when I deleted those divs, it went to the <div class="col-md-3" line. – user55305 Dec 15 '15 at 21:38
  • Please ensure that PHP code is correctly enclosed within the PHP tags. – Pallavi Sugandhi Dec 16 '15 at 5:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.