drupal 7

A Drupal 7 form table example

If you're interested in building an HTML table with Drupal, Drupal 7 in this case, here's a quick example of how this can be done.

My Drupal "theme table" approach currently provides the following functionality:

A Drupal form select/options field example (dropdown box)

Drupal form FAQ: How do I create an HTML SELECT/OPTIONS field in a Drupal form?

Solution: If you'd like to create an HTML SELECT field (a dropdown box) in a Drupal form that looks something like this:

A Drupal 7 form SELECT OPTIONS field example

there are at least two ways to do so.

A Drupal 7 db_insert query (SQL INSERT statement)

Drupal 7 database FAQ: How do I use the Drupal dbquery function to perform a SQL INSERT? (Or, what is the Drupal 7 dbinsert syntax?)

I didn't type db_query in that question by mistake. I just spent 45 minutes trying to use it for a Drupal 7 SQL INSERT, which of course I've now learned doesn't work.

In short, if you're looking for a Drupal 7 db_insert example that shows how to perform a SQL INSERT, and also happens to show some SQL Timestamp fields, here's a 'submit' function I'm currently writing:

A Drupal get user id function (uid)

Just a quick note here to share a Drupal get user id (uid) function. I've found that when I'm developing a Drupal module or Drupal application, I often need to access the user id, so I created this simple function and include it in a common utilities module:

# return the current drupal user id (uid)
function get_user_id() {
  global $user;
  return $user->uid;
}

As you can see, the code accesses the global Drupal user object ($user), then gets the uid from the user object.

A Drupal theme table example

Summary: A Drupal "theme table" example, where I show how to generate an HTML table from a Drupal module, using the Drupal theme function (and specifically not the theme_table function).

How to change a Drupal 6 user password using mysql or phpmyadmin

Drupal 6 FAQ: How can I change the password of a Drupal user in the database without using the Drupal UI? That is, how can I change a user's password using a database query (such as the need to change the Drupal User 1 password)?

If you ever want/need to change a Drupal 6 user password in your database using the MySQL command line or a tool like PhpMyAdmin, a SQL query like this will do the trick:

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: