webform_hints.module in Webform Hints 6
File
webform_hints.module
View source
<?php
function webform_hints_init() {
drupal_add_js(drupal_get_path('module', 'webform_hints') . '/jquery.formHints.js');
drupal_add_js(drupal_get_path('module', 'webform_hints') . '/webform_hints.js');
}
function webform_hints_perm() {
return array(
'administer Webform Hints settings',
);
}
function webform_hints_menu() {
$items = array();
$items['admin/settings/webform-hints'] = array(
'title' => 'Webform Hints',
'description' => 'Administer which of your Webforms will receive the hints effect.',
'file' => 'webform_hints.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'webform_hints_admin_settings',
),
'access arguments' => array(
'administer Webform Hints settings',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function webform_hints_form_alter(&$form, $form_state, $form_id) {
$webforms = array_values(variable_get('webform_hints_forms', array()));
if (substr($form_id, 0, 20) == 'webform_client_form_') {
if (in_array($form['#node']->nid, $webforms)) {
$form['#attributes']['class'] .= ' webform-hints';
array_walk($form['submitted'], 'webform_hints_add_title');
}
}
}
function webform_hints_add_title(&$element) {
if (is_array($element)) {
$fieldtypes = array(
'textfield',
'textarea',
'webform_email',
'email',
);
if (in_array($element['#type'], $fieldtypes)) {
$element['#attributes']['title'] = $element['#title'];
$element['#attributes']['placeholder'] = $element['#title'];
}
}
}