drupal

recent posts related to the drupal content management system

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 6 - The CKEditor is removing/deleting CODE tags

I had a problem using the CKEditor with Drupal 6 where the CKEditor would not display <code> tags properly in the editor, and would then delete trailing spaces after the <code> tag. After some digging around, I finally found that I needed to comment out the following line in the ckeditor.config.js of my CKEditor module installation:

Creating new devdaily content types with Drupal CCK and Views

I haven't gotten around to formatting the pages that you'll see just yet, but a cool thing about Drupal is that with the CCK and Views modules, you can very easily create and then display new "content types" on your websites.

For example, I just added the following content types to the devdaily website:

Drupal front page - Removing the H1 title tag

Drupal FAQ: How do I remove the H1 title tag from the front page of a Drupal website?

I just ran into this problem on my new website, How I Sold My Business: A Personal Diary. Whenever you create a Drupal page you have to give it a title, but for the front page of a website that doesn't really make sense.

There are at least two ways to do this:

Drupal - How to modify the node/page title for a custom content type

Drupal content type FAQ: How do I modify the node title for the "create" form when I add a new content type?

For my How I Sold My Business website, I added a new, custom content type named "Charity". This allows people who have bought my book to suggest a charity. The problem with this is that I want the Charity node title (also referred to as a "page title") to say "Suggest a Charity", not the default "Create Charity".

Drupal - How to redirect a user when altering an existing form

Drupal form FAQ: How do I redirect a user when they submit a form, and I'm writing a hook_form_alter function to alter that form?

In Drupal 6 you set the "$form['#redirect']" property in your hook_form_alter function when you alter the form, like this:

$form['#redirect'] = 'thank-you';

That syntax tells Drupal to redirect the user to the "/thank-you" URI on your website.

Here's the source code for a full hook_form_alter function I just pulled from a working Drupal module:

Drupal CCK form field - US states list

If you're ever creating a Drupal form using the CCK module and need to show a list of states (the United States) in a combo box (also known as a "select list" or "drop down" field), you'll want to have that list of states in the right format.

Fortunately (for you) I just ran into this problem, and created two different versions of CCK form state fields. This first one displays the full name of the state, and stores the two-digit state code in the database:

Drupal form and module debugging

Drupal debugging FAQ: How can I debug my Drupal form and module development process?

I should know more about this over the next few weeks, but if you're developing Drupal forms and modules, I've found the PHP error_log function and the Drupal watchdog function to be very helpful. They both let you log errors 'somewhere', and the error_log output shows up in your Apache logs, and the watchdog output shows up in your Drupal reports.

Here's how you call the PHP error log function:

Drupal developer modules

Once you get into serious Drupal module development, you'll realize that it would be really helpful if you could do several things during the module development process, including clearing the cache, rebuilding the menus, error logging (logging errors to a file, in particular), and so on. Fortunately, with Drupal's really large developer ecosystem, other Drupal programmers have already created some great modules to help you along in the coding process.

Here's a list of the Drupal developer modules I currently use, or have used.

A Drupal form states dropdown field (list of states) example

I was just working on a Drupal form, and I wanted to include a list of states (the United States) in a dropdown field (an HTML select/options field). Knowing that I'll need this list of states for other Drupal applications, I decided to put the "states" code in a separate file.

To that end I put this list of states in a file named states.inc, in the same directory with the rest of my Drupal module code:

Syndicate content