drupal 6

Manual PHP and Drupal 6 web access logging

There was a little funky activity on a client's Drupal 6 website that was hosted at GoDaddy, and without having access to an Apache access log file, I wanted to be able to see what was going on. So I wrote the following PHP code snippet to do some manual logging, and placed it in the Drupal theme's page.tpl.php file:

Drupal form default input focus

Drupal form FAQ: How do I get default input focus on a Drupal form field (presumably a form textfield)?

There may be a better way to do this, but here's what I just did to get default input focus on a series of Drupal form 'add' and 'edit' pages. I just included the following Drupal form suffix definition on any form where I wanted to control the default input focus:

Handling Drupal SQL exceptions (db_insert, db_update, db_delete)

While developing a Drupal module, I just ran into a situation where it may be common for users to generate SQL exceptions. I have a 'unique' limit on several of my database tables, essentially saying that certain name fields must be unique for the current project. As you can imagine, it's extremely easy to enter a duplicate name, and while doing a SQL INSERT that can easily lead to a SQL exception.

As a result, I dug around and found a way to handle SQL exceptions in Drupal queries. My current problem is with a Drupal 7 db_insert query, and I handled it like this:

25+ Drupal form and module programming examples

This page serves as an index to all of my Drupal module, form, and databases tutorials and examples. In an effort to help supplement the documentation on the Drupal.org website, over time I hope to have good examples for every Drupal module and form problem you'll run into.

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 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.

Create a Drupal table list view from a Drupal module

Drupal table view FAQ: How do I create a simple Drupal table view in Drupal module? I want to create a simple "list view", the sort of list view you might see in a simple CRUD application.

I just ran into this Drupal "table list" problem while creating a Drupal module, and after a lot of digging around, I found a formula that lets me display a Drupal table view like this:

Drupal APC performance improvements

Summary: A look at the performance improvements gained on a Drupal 6 website by using the PHP APC Opcode Cache.

Wow, I just installed the PHP APC Opcode Cache module on devdaily.com, and the results are really incredible. By any metric the website is performing much, much faster.

I ran two benchmarks on the website using the Apache 'ab' benchmarking tool, one without the APC opcode cache, and one with it.

Drupal 6 image errors and solutions (ImageCache, ImageField, CCK)

After just creating another Drupal 6 website that uses ImageCache, ImageAPI, ImageToolkit, CCK, and ImageField, I thought I'd make some notes here about the problems I ran into when trying to use ImageField with CCK to let users upload images to my website. I encountered several very frustrating errors along the way, and here are my notes related to those errors.

Note: This blog post is about Drupal 6. Things have changed quite a bit in Drupal 7, and these tips are not likely to be helpful there.

How to change a Drupal user password using mysql or phpmyadmin

Drupal 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:

Syndicate content