How do I get it to work with another standard drupal form(say register etc.)?Can I add custom text inside the textfield,and will it override the default description for that field?
Thanks.

Comments

quicksketch’s picture

In any form definition or hook_form_alter(), you just set $element['#hint'] = 'something'; to set a hint. I think the README.txt lays out how to use the API. There is not plan to provide further "built-in" hints, the ones that are there are just the most common and provide good examples.

mautumn’s picture

I spent ages trying to figure this out and got there in the end. I couldn't find a complete example and was taken down misleading or dead-end routes. Here is a complete working example for those looking to do this. Hopefully it will save you a lot of hassel.

A simple hook_for_alter() function is all that is required with the following snippet :-

function mymodule_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
        case 'my_form_id':
            hint_set_hint($form['my_form_name']['my_input_field_id'], t('Enter your search here...'));
            break;
    }
}

The key is finding out the form_id ('my_form_id' above), the form name ('my_form_name' above), and the id of the input element ('my_input_field_id' above). A print_r($form) above the switch statement is a way to find these values. Interpreting the form API hierarchical array is another matter! (The switch statement is used just in case your form alter function does things with other forms.)

This will work with multiple input fields on the same form (e.g. CCK fields) and will also work on multiple forms - i.e. many sub-forms on a page (e.g. in panels, blocks, etc.).

Thanks quicksketch for yet another useful module. Your work is really appreciated.

quicksketch’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.