Collapsible Fieldsets Without jQuery

Attached File(s): 

c_fieldset.jpgYou know those nifty collapsible fieldsets that Drupal uses?  No?  Oh... well, let me explain: Drupal often uses fieldsets to represent information, which can collapse at the click of a mouse.  This lets visitors to your site hide information or forms they don't care about.  It's accomplished using some jQuery wizardry and is uber slick.

What I have created does not use jQuery, and is not uber slick.  But, it does provide the same basic functionality.  The reason I chose not to use jQuery is so that you are not required to download and install any extra libraries.

What I have created is a simple PHP function which, when called, will generate all of the HTML, CSS, and Javascript necessary to give you a collapsible fieldset.

Click here to see a demo of it in action.  (And use the download link at the top of this post to get the source code).

The idea is you just include the function c_fieldset in your source code, then call it like this:

print c_fieldset("This is my content", "My Title");

And you do not need to worry about any extra jQuery libraries.

So there you go.


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (, NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.