Would it be possible to transfer the elements / options from one fieldset to another?

-Fieldset
-- Name
-- Age
-Fieldset
-- Sex

Lets say that from the above i would like sex to be moved to the above fieldset and not have it's own.

Why? I have some notify modules, like for comments and PM's, but the notify module for PM has its own fieldset. It's more logical to have one fieldset with the name "Notify" and have all the notification options in there.

Comments

nevets’s picture

Yes, each field set element will have a key, I will call the f1 and f2, this code should get you started.

// The fieldset we want to move form elements from
$source = 'f2';
// The fieldset we want to move form elements to
$target= 'f1';
foreach ( element_children($form[$source]) as $key => $child ) {
  $form[$target][$key] = $child;
}
unset($form[$source]);

You would need a module that implement hook_form_alter() with code to check the form id and uses code like the above.

Michsk’s picture

Thanks, i will look in to it today.

Michsk’s picture

What do you mean with 'key'? I can not find any key nor an id for the fieldsets...

  ["comment_notify_settings"]=>
  array(7) {
    ["#type"]=>
    string(8) "fieldset"
    ["#title"]=>
    string(39) "E-mail melding van berichten & reacties"
    ["#weight"]=>
    int(3)
    ["#collapsible"]=>
    bool(true)
    ["node_notify_mailalert"]=>
    array(4) {
      ["#type"]=>
      string(8) "checkbox"
      ["#title"]=>
      string(81) "E-mail melding ontvangen wanneer er een reactie wordt geplaatst op mijn berichten"
      ["#default_value"]=>
      string(1) "0"
      ["#description"]=>
      string(167) "Plaats hierboven een vinkje wanneer u e-mail meldingen wilt ontvangen bij reacties op uw berichten. Dit kunnen reacties zijn op dagboekbladzijdes en forum onderwerpen."
    }
    ["comment_notify_mailalert"]=>
    array(5) {
      ["#type"]=>
      string(6) "select"
      ["#title"]=>
      string(41) "E-mail melding bij reacties op uw reactie"
      ["#default_value"]=>
      string(1) "0"
      ["#options"]=>
      array(2) {
        [0]=>
        string(33) "Geen e-mail meldingen op reacties"
        [1]=>
        string(13) "Alle reacties"
      }
      ["#description"]=>
      string(195) "Kies hierboven op welke reacties u via e-mail op de hoogte gehouden wilt worden. Bijvoorbeeld: reacties op uw reactie. Wanneer er iemand reageert op uw reactie dan ontvangt u daarover een e-mail."
    }
    ["#collapsed"]=>
    bool(true)
  }
Michsk’s picture

I get the idea. But i also get a error :-P

Fatal error: Cannot use string offset as an array in /var/www/vhosts/##.nl/subdomains/##/httpdocs/includes/form.inc  on line 986
	// The fieldset we want to move form elements from
	$source = 'enable_pm_mail';
	// The fieldset we want to move form elements to
	$target= 'comment_notify_settings';
	foreach ( element_children($form[$source]) as $key => $child ) {
	  $form[$target][$key] = $child;
	}
	unset($form['enable_pm_mail']);
Michsk’s picture

Got this working with:

	// The fieldset we want to move form elements to
	$target= 'comment_notify_settings';
	foreach ( $form['enable_pm_mail']['pm_send_notifications'] as $key => $child ) {
	  $form[$target]['pm_send_notifications'][$key] = $child;
	  //print $child;
	}
	unset($form['enable_pm_mail']);
lelizondo’s picture

This is great. Thanks.

Luis