drupal

recent posts related to the drupal content management system

Drupal CCK module - How to hide the Body field

Some times you just have to laugh at yourself ... I was just struggling to figure out how to hide the Body field on a new CCK form, and just as I was thinking I might have to resort to some jQuery magic, I finally read the help text under the Body field on the CCK "Submission Form Settings":

To omit the body field for this content type, remove any text and leave this field blank.

Drupal canonical meta tags for pager URLs

As a quick note, I was just about to write a Drupal 6 module to add "rel=canonical" meta tags to Drupal pager pages (pager URLs), so URLs that look like this:

http://www.devdaily.com/blog?page=47

or this:

A Drupal Views tutorial

This is a tutorial on how to create a view using the Drupal Views module. In this example I'll be creating a simple view of the Drupal 'comments' database table. I'll demonstrate how to create this viewas a Drupal node with an associated URL and menu item, so when you're done you'll be able to access it at a URL like:

A Drupal fieldset example (Drupal form group)

Drupal form fieldset FAQ: How do I build a Drupal form using one or more fieldset areas to group my form elements into logical components (like 'shipping address', 'billing address', 'credit card information', and so on)?

As inferred by the question, you group Drupal form elements using the Drupal fieldset element. You define a fieldset, then add form elements to that fieldset using a simple sub-array syntax. For example, in the following Drupal source code example I define a fieldset using an array like this:

The Drupal fieldset collapsible syntax

Drupal fieldset FAQ: What is the syntax to make a Drupal fieldset (form fieldset) collapsible?

To make a Drupal form fieldset collapsible, just add the "#collapsible" attribute to your Drupal form definition, like this:

The Drupal fieldset initially collapsed syntax

Drupal fieldset FAQ: How do I make a Drupal fieldset initially collapsed?

To make a Drupal fieldset collapsed initially, make the fieldset collapsible, then set the "collapsed" property TRUE, like this:

The Drupal form field required syntax

Drupal form fields FAQ: What is the syntax to make a Drupal form field (textfield, textarea, password field) required?

To make a Drupal form field required, just use the Drupal form #required attribute, as shown in this required textfield example:

$form['first_name'] = array(
  '#title' => t('First Name'),
  '#type' => 'textfield',
  '#required' => TRUE,
);

As you can see, to set a Drupal form field to be required, you just need to add the #required form attribute, and set it to TRUE.

 

Drupal form textfield help text (description) syntax

Drupal form textfield FAQ: How do I set the "help" text for a Drupal form textfield?

The help text that you normally see with a Drupal textfield comes from the Drupal form "#description" attribute. Here's a quick example:

Drupal form textfield default value syntax

Drupal form textfield FAQ: How do I set the default value for a textfield in a Drupal form?

Just use the Drupal form "#default_value" tag, like this:

$form['first_name'] = array(
  '#title' => t('First Name'),
  '#type' => 'textfield',
  '#default_value' => 'John',
);

Here's an example of setting the default value of a Drupal textfield to a variable instead of a static text string:

Drupal form textfield required syntax

Drupal form textfield FAQ: What is the syntax to make a Drupal textfield required?

Just use the Drupal form #required property, like this:

$form['first_name'] = array(
  '#title' => t('First Name'),
  '#type' => 'textfield',
  '#required' => TRUE,
);

In that example the Drupal form textfield is made required by setting the "#required" tag equal to TRUE.

 

Syndicate content