0

I've been trying to insert a placeholder for my search-bar, so in my page.preprocess.inc I call hook_form_search_block_form_alter(), then specify the form's array, and create the placeholder array, but it doesn't work. I've tried multiple things but none of them seem to affect the form in any way. I use devel themer, as both the devel page array and <?php dpm() ?> don't seem to work on my frontpage. My alternative would be to use jquery but I'd rather have this work then having to resort to the longer method.

Here's what I'm working with:

theme name - hitech_wolf

EDIT: I'm using omega4

PAGE.PREPROCESS.INC

    <?php
        // Can Ignore, left in here just in case it influences the alter statement 
        /**
         * Implements hook_preprocess_page().
         */
        function hitech_wolf_preprocess_page(&$variables) {
            $path = drupal_get_path('theme','hitech_wolf');
            drupal_add_js($path . '/js/iframe_colorbox_support.js');
        }

        /**
         * Implements hook_form_alter().
         */
    // Separate Attempts - present for example
    function hitech_wolf_form_search_block_form_alter(&$form, &$form_state) {
      $form['search_block_form']['#placeholder'] = array(
        t('Search...'),
      ); 
    }
    function hitech_wolf_form_search_block_form_alter(&$form, &$form_state) {
      $form['search_block_form']['#attributes'] = array(
        'placeholder' => t('Search...'),
      ); 
    }
    function hitech_wolf_form_alter(&$form, &$form_state) {
      if ($form_id == 'search_block_form') {
        $form['search_block_form']['#attributes']['#placeholder'] = t('Request your username');
      }
      if ($form_id == 'search_block_form') {
        $form['search_block_form']['#attributes'] = array('placeholder' => t('Request your username') 
    );
  }
}
        // Check if anything works at all - doesn't
        function hitech_wolf_form_alter(&$form, &$form_state, $form_id) {
          hide($form);
        }
        function hitech_wolf_form_alter(&$form, &$form_state, $form_id) {
          unset($form);
        }

PICTURES - form id/location form id form location

  • Have you seen this? It's specific to Omega but you haven't mentioned which base theme you're using... – Darvanen Dec 4 '14 at 0:52
  • Also I'm pretty sure <?php dpm() ?> isn't working for you because you need to give it an argument. – Darvanen Dec 4 '14 at 0:56
  • sorry my base-theme is indeed omega, and I've tried <?php dpm() ?>, and <?php dpm($variables) ?>, I'm trying your link now, thanks for the info, hopefully it works. – Bakajuice Dec 4 '14 at 1:03
  • nope alpha doesn't help, also the previous preprocess works without alpha, thanks anyhow :) – Bakajuice Dec 4 '14 at 1:10
  • Two other things: you can't call a hook twice in the same file, and maybe you haven't cleared your cache after editing the hooks? – Darvanen Dec 4 '14 at 1:13
2

hook_form_alter() belongs to template.php, or in a module, as only there it can be recognized; it doesn't work the same as preprocess functions. See also this Reddit.

| improve this answer | |
  • Thanks kiamlaluno, I had a feeling that was the case but couldn't find the documentation on it so I didn't want to say it. – Darvanen Dec 4 '14 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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