Drupal Form API: form_set_error() on a fieldset element.

|

Ever tried to set an error to a fieldset element in the form validate function (form_set_error function)? I tried it and it didn't work. So after some digging around form.inc I found the answer (a clean fix at that!).

Tutorial Requirements:

  • Drupal 5.
  • PHPTemplate based theme.
  • Know how to do a quick Copy and Paste.

First you will open your form.inc file and copy the theme_fieldset() function. Next open your template.php file that can be found in your theme folder (if you are using garland /themes/garland, if your using another theme look for its folder). You will then paste the function in that template.php file and make just a few changes.

<?php
/**
* Format a group of form items.
*
* @param $element
*   An associative array containing the properties of the element.
*   Properties used: attributes, title, value, description, children, collapsible, collapsed
* @return
*   A themed HTML string representing the form item group.
*/
function theme_fieldset($element) {
  if (
$element['#collapsible']) {
   
drupal_add_js('misc/collapse.js');

    if (!isset(
$element['#attributes']['class'])) {
     
$element['#attributes']['class'] = '';
    }

   
$element['#attributes']['class'] .= ' collapsible';
    if (
$element['#collapsed']) {
    
$element['#attributes']['class'] .= ' collapsed';
    }
  }

  return
'<fieldset' . drupal_attributes($element['#attributes']) .'>' . ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . ($element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . $element['#children'] . $element['#value'] . "</fieldset>\n";
}
?>

What needs to happen is we need to override the this themable function in our theme so that we can change the way that the fieldset elements are output. This is one of Drupal's greatest assets, a simple, clean approach to overriding the standard Drupal output.

So after copying that function into your template.php file you need to make a few modifications, change the function name to "phptemplate_fieldset" and add a sinle extra line of code:

<?php
  _form_set_class
($element);
?>

So let's put it all together and see what the function becomes:

<?php
/**
* Format a group of form items.
*
* @param $element
*   An associative array containing the properties of the element.
*   Properties used: attributes, title, value, description, children, collapsible, collapsed
* @return
*   A themed HTML string representing the form item group.
*/
function phptemplate_fieldset($element) {
  if (
$element['#collapsible']) {
   
drupal_add_js('misc/collapse.js');

    if (!isset(
$element['#attributes']['class'])) {
     
$element['#attributes']['class'] = '';
    }

   
$element['#attributes']['class'] .= ' collapsible';
    if (
$element['#collapsed']) {
    
$element['#attributes']['class'] .= ' collapsed';
    }
  }
 
_form_set_class($element);
  return
'<fieldset' . drupal_attributes($element['#attributes']) .'>' . ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . ($element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . $element['#children'] . $element['#value'] . "</fieldset>\n";
}
?>

Voila, you now have a .error class attached to the fieldset html element after setting a form error using the form_set_error function.

After using this a bit

After using this a bit further I found some errors showing up on the modules administration screen (all else is working fine). I'm still working on this but will post up a fix when I can figure the issue out.

Thanks you very good; thanks

Thank you very much for this

Thank you very much for this information.
Good post thanks for sharing.
I like this site ;)
-----------
gögüs büyütücü
zayiflama

parça kontör parça

parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör
parça kontör parça kontör parça kontör parça kontör parça kontor parça kontor parça kontor parça kontor
parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor
sohbet chat mirc muhabbet sanal sohbet cet emlak gayrimenkul oto
araba muhabbet chat sohbet mirc irc sanalalem kelebekirc sohbetalemi sanalmuhabbet
kralchat arkadas msn muhabbet sohbet sanal chat mirc arkada? cet
oyun pc oyunoyna mp3 müzik radyo adult magazin haber adult
parça kontör parca kontor kontör ucuz kontör parça kontör parça kontör parça kontör parca kontor kontör ucuz kontör
sohbet sohbet haber mirc script video izle otomobil chat muhabbet sanal
adult adult adult adult adult adult adult adult otomobil otomobil
otomobil otomobil otomobil otomobil otomobil otomobil otomobil otomobil otomobil
otomobil automobile automobile automobile automobile automobile automobile automobile automobile
automobile automobile automobile automobile mirc mirc mirc mirc mirc mirc
mirc mirc mirc mirc mirc mirc haber haber haber haber
haber haber haber haber haber haber haber haber futbol futbol
futbol futbol futbol futbol futbol futbol futbol futbol futbol futbol
resim resim resim resim resim resim resim resim resim resim
resim resim web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m
web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m

parça kontör parça

parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör
parça kontör parça kontör parça kontör parça kontör parça kontor parça kontor parça kontor parça kontor
parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor
sohbet chat mirc muhabbet sanal sohbet cet emlak gayrimenkul oto
araba muhabbet chat sohbet mirc irc sanalalem kelebekirc sohbetalemi sanalmuhabbet
kralchat arkadas msn muhabbet sohbet sanal chat mirc arkada? cet
oyun pc oyunoyna mp3 müzik radyo adult magazin haber adult
parça kontör parca kontor kontör ucuz kontör parça kontör parça kontör parça kontör parca kontor kontör ucuz kontör
sohbet sohbet haber mirc script video izle otomobil chat muhabbet sanal
adult adult adult adult adult adult adult adult otomobil otomobil
otomobil otomobil otomobil otomobil otomobil otomobil otomobil otomobil otomobil
otomobil automobile automobile automobile automobile automobile automobile automobile automobile
automobile automobile automobile automobile mirc mirc mirc mirc mirc mirc
mirc mirc mirc mirc mirc mirc haber haber haber haber
haber haber haber haber haber haber haber haber futbol futbol
futbol futbol futbol futbol futbol futbol futbol futbol futbol futbol
resim resim resim resim resim resim resim resim resim resim
resim resim web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m
web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m

parça kontör parça

parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör parça kontör
parça kontör parça kontör parça kontör parça kontör parça kontor parça kontor parça kontor parça kontor
parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor parça kontor
sohbet chat mirc muhabbet sanal sohbet cet emlak gayrimenkul oto
araba muhabbet chat sohbet mirc irc sanalalem kelebekirc sohbetalemi sanalmuhabbet
kralchat arkadas msn muhabbet sohbet sanal chat mirc arkada? cet
oyun pc oyunoyna mp3 müzik radyo adult magazin haber adult
parça kontör parca kontor kontör ucuz kontör parça kontör parça kontör parça kontör parca kontor kontör ucuz kontör
sohbet sohbet haber mirc script video izle otomobil chat muhabbet sanal
adult adult adult adult adult adult adult adult otomobil otomobil
otomobil otomobil otomobil otomobil otomobil otomobil otomobil otomobil otomobil
otomobil automobile automobile automobile automobile automobile automobile automobile automobile
automobile automobile automobile automobile mirc mirc mirc mirc mirc mirc
mirc mirc mirc mirc mirc mirc haber haber haber haber
haber haber haber haber haber haber haber haber futbol futbol
futbol futbol futbol futbol futbol futbol futbol futbol futbol futbol
resim resim resim resim resim resim resim resim resim resim
resim resim web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m
web tasar?m web tasar?m web tasar?m web tasar?m web tasar?m

Thanks you very good; thanks

great system

great system

very good. nice gallery.

very good. nice gallery. trsohbet, sohbet, chat, sohbet odalar?, sohbet sitesi, chat sohbet, çet, sohbet odalari, chatsohbet, sohbet chat, sohbet com, sohpet, kameral? sohbet, arkada?l?k, e?lence, kad?nidealsohbet, sohbet, chat, sohbet odalar?, sohbet sitesi,
chat sohbet, chatsohbet, sohbet chat, sesli sohbet, sohbet com, sohpet, kameral? sohbet, islami sohbet, gurbet sohbet, çet, ideal script sohbet ve sohbet odalar? chat de olabilirsohbet sevgi f?kra sevgi sözleri oyun kelebek türkçe mirc mirc indir k?z msnleri sohbet mirc youtube okey spor haberleri okey indir okey indir indir-indir.net Sohbet.Org, Sohbet, Chat, Sohbet Odalar?, Chat Sohbet, Sohbet Chat, Türk Sohbet, Sohbet Sitesi, Org Chat, Sohbet Chat Org, Chat Sohbet Org, SohbetOrg, Chat Org, Türkiye Sohbet Chat, C?hat Sohbet, Sohbet Turk, Türklerin Sohbet Odalari, Chat Sayfas? çet, sohbet kanallar?, sohbet odalar?, kameral? sohbet, arkada?l?k, mizah, ve di?er bölümlerde Astroloji, Galeri, Gazete, linkleri mirc download,mirc komutlar?, ve sohbet, bir de?i?le sohbet,ve mynet sohbet
chat

Thanks for very interesting

Thanks for very interesting article. btw. I really enjoyed reading all of your posts. It’s interesting to read ideas, and observations from someone else’s point of view… makes you think more. So please keep up the great work. Greetings.
Flash Drive|Flash Card| Memory Module| Memory Card|citysgirl
Electronic Manufacturing Services| China Electronic Manufacturer|Electronics Manufacturer| Electronics Manufacturing China| China Electronics Manufacturers|
ealthyirenseefashiongirlfashionflygirlfashiongirlsky986
onlinehkflyshy2008fashiongirlfashionsaleisha-lifefashionlifefashionfashiongirl
????

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

Upcoming events

  • No upcoming events available