0
votes

I kind of know the basics about Drupal theming when it comes to templates. However, I have no idea on how to change forms that are used on the site.

I am using Commerce Kickstart with a the Omega Kickstart theme. There are a couple of forms like the search box or the add-to-cart form.

I did some research and came up to something like this for my themes template.php:

<?php  
function mytheme_form_alter(&$form, &$form_state, $form_id){
  if($form_id == "form_id") {
  $form['form_id']['#title'] = t('Something');
  }
}

I tried this to change the placeholder that is shown in the searchbar:

<?php  
function mytheme_form_alter(&$form, &$form_state, $form_id){
  if($form_id == "edit_search_api_views_fulltext") {
  $form['edit_search_api_views_fulltext']['#attributes']['placeholder']= t('Something');
  }
}

I used edit_search_api_views_fulltext because when I inspect the website code, it shows me the id=edit-search-api-views-fulltext. However, when I use a module that is supposed to print out the ids of forms on the Drupal page, it shows me something like id=views-exposed-form wich didnt work and doesnt seem to be right either.

So my question is how can I access that form and change what I want? And where is the HTML of that form even located? I wasnt able to find it at all.

1
views-exposed-form = Module Views , you need to change DisplayHandler gist.github.com/rafinskipg/4001140 - Fky
@Fky to be honest, I have no idea what that means for me. Could you go a bit more into detail? - user8680885
Your form is generated by Views module , it's an exposed form. So you need to modify its display . You can find your view on path /admin/structure/views - Fky
Since the Block that contains the search bar is called "Exposed form: display_products-page" I guess I have to search in "Display Products" view. But no Idea what to do from there. Its just a representation of the search result but I cant find anything about the form - user8680885

1 Answers

0
votes
function hook_form_alter(&$form, &$form_state, $form_id){
    switch ($form_id)

    case 'views_exposed_form':
        switch ($form['#id']) {
            case 'views-exposed-form-calendar':
                $form['search-phrase']['#attributes']['placeholder'] = t('Search All Calendar');

                break;
        }
        break;
}}

You have to check correct $form['#id'] when you working with 'views-exposed-form'