Webform placeholders

Public

</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_form_alter().
  3.  */
  4. function HOOK_alter_form_alter(&$form, &$form_state, $form_id) {
  5. if (substr($form_id, 0, strlen('webform_client_form_')) == 'webform_client_form_') {
  6. $form['#after_build'][] = 'HOOK_alter_form_after_build';
  7. }
  8. }
  9. function HOOK_alter_form_after_build(&$form, &$form_state) {
  10. foreach($form['submitted'] as $possible_fieldset_key => &$fields) {
  11. // If is fieldset
  12. if (substr($possible_fieldset_key, 0, 1) != '#') {
  13. foreach ($fields as $possible_field_key => &$field_data) {
  14. if (substr($possible_field_key, 0, 1) != '#') {
  15. $field_data['#attributes']['placeholder'] = $field_data['#title'];
  16. }
  17. }
  18. }
  19. }
  20. return $form;
  21. }

Comments

rudiedirkx's picture

Isn't this possible directly in the form alter? You can add #attributes there, right?