2

I set up a site in drupal, and I need to show the fields of date type in the same way as other fields. the problem is that those fields are inside a fieldset.

I'm try the solution code karate, buts it only changes the fieldset to a label.

my attempt

What I want is showing those fields outside a fieldset, stay equal to the remaining fields.

I am using the following code.

/**
 * Remove fieldset from date inputs
 */
function mytheme_date_combo($variables) {
    dd($variables);
    return theme('form_element', $variables);
}
  • Why don't you just hide the label with CSS, #edit-field-data-de-nascimento .form-type-date-combo label { display:none; }? – Sk8erPeter Dec 14 '12 at 1:07
  • because resolve this problem with css is a bad practice. users may have deactivated the css. – Miguel Borges Dec 14 '12 at 1:35
  • 2
    are you serious? :) This sounds really funny. Which user deactivates using CSS? 0.01% of the users? If the user keeps the CSS disabled, he/she will experience larger "problems" (?) than seeing the form element's label. Not to mention that even the core CSS stylesheets hide many information with using regular CSS to keep some information still readable by screen readers!! So NO, resolving this issue with CSS is NOT a bad practice. – Sk8erPeter Dec 14 '12 at 2:20
  • 1
    NO, I didn't forget about users that use accessibility programs, this is exactly what I was talking about when saying Not to mention that even the core CSS stylesheets hide many information with using regular CSS to keep some information still readable by screen readers! – Sk8erPeter Dec 16 '12 at 2:26
  • 3
    possible duplicate of Remove fieldset from date field – Yusef Aug 20 '15 at 11:01
2

Well you try this way

hook_form_alter

Perform alterations before a form is rendered.

One popular use of this hook is to add form elements to the node form. When altering a node form, the node object can be accessed at $form['#node'].

This is the idea

<?php
function example_form_alter(&$form, &$form_state, $form_id) {
  // If Devel Installed 
  dsm($form_id);  // print form ID to messages
  dsm($form);  // pretty print array using Krumo to messages
  // If no Devel
  print $form_id;
  // 1. Find the From ID of the Form
  // 2. Check the Form Structure and Remove the Field Set.
}
?>

Here is Form API Reference

  • hook_form_alter() is preferable than implementing a theme function that would alter a form element in any form using it. – kiamlaluno Dec 14 '12 at 9:25
  • @kiamlaluno, sorry i dont understand. Can you elaborate ? Can we move to chat ? – niksmac Dec 14 '12 at 9:28
  • I am just saying that your solution is better than implementing theme_date_combo() as the OP is doing. theme_date_combo() alters how the date field is rendered for every form. It is more probable the OP needs to alter specific date fields in specific forms, rather than changing every date field. – kiamlaluno Dec 14 '12 at 9:42
  • thx for reply. My goal was even modify all fields of date type, ie, remove the fieldset, replacing the legend with a normal label, and remove the label that is inside the fieldset. – Miguel Borges Dec 16 '12 at 1:19
3

I used a patch from an issue queue in drupal to sort me out on that one. I should say it works well for me. You can find it here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.