Guest User

Untitled

a guest
Feb 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. $form['name'] => array(
  2. '#type' => 'textfield',
  3. '#title' => 'Prénom'
  4. );
  5.  
  6. $form['name']['#attributes']['class'] = array('myClass');
  7.  
  8. $form['name'] => array(
  9. '#type' => 'textfield',
  10. '#title' => 'Prénom'
  11. '#prefix' => '<div class="myClass">',
  12. '#suffix' => '</div>'
  13. );
  14.  
  15. .myClass label {
  16. text-transform: uppercase; /* just for example */
  17. }
  18.  
  19. .form-item-field-foo label {
  20. /* CSS here */
  21. }
  22.  
  23. function mymodule_form_alter(&$form, $form_state, $form_id) {
  24. switch ($form_id) {
  25. // Waterfall.
  26. case 'webform_client_form_16':
  27. case 'webform_client_form_51':
  28. case 'webform_client_form_64':
  29. case 'webform_client_form_78':
  30. $exclude = array('select', 'radios', 'checkboxes', 'managed_file');
  31. foreach ($form['submitted'] as $name => $component) {
  32. if (!in_array($component['#type'], $exclude) && $name != '#tree') {
  33. $form['submitted'][$name]['#prefix'] = '<span class= "label-invisible">';
  34. $form['submitted'][$name]['#suffix'] = '</span>';
  35. $form['submitted'][$name]['#attributes']['placeholder'] = $component['#title'];
  36. }
  37. }
  38. $form['#attached']['css'] = array(
  39. drupal_get_path('module', 'mymodule') . '/css/mymodule.form.css',
  40. );
  41. break;
  42. }
  43. }
  44.  
  45. <span class="field-label"<?php print $title_attributes; ?>>
  46. <?php print $label; ?>:
  47. </span>
  48.  
  49. <span class="<?php print $label; ?> field-label"<?php print $title_attributes; ?>>
  50. <?php print $label; ?>:
  51. </span>
  52.  
  53. $form['some_element'] = array(
  54. '#type' => 'textfield',
  55. '#title' => '<span title="HELP!">'.t($subchildlabel).'</span>',
  56. '#default_value' => …
  57. )
  58. );
  59.  
  60. <label for="edit-m-vernacularname" class="inline"><span title="HELP!">Common name
  61. </span> </label>
  62.  
  63. function your_module_preprocess_form_element(&$variables) {
  64.  
  65. $element = $variables['element'];
  66. if (isset($element['#label_attributes'])) {
  67. $variables['label']['#attributes'] = array_merge(
  68. $variables['attributes'],
  69. $element['#label_attributes']
  70. );
  71. }
  72. }
  73.  
  74. $form['some_field'] = [
  75. [...]
  76. '#label_attributes' => [
  77. 'some_attr' => 'some_value',
  78. ]
  79. ]
Add Comment
Please, Sign In to add comment