Drupal Logo

Drupal 6 Form Elements Example Module

21st September 2011 - 8 minutes read time

During my work developing Drupal sites I am quite often asked if I can provide a example of form elements for designers. This is so that they can test their designs with all possible form elements that might appear in a Drupal install and make sure that the theme we create will be robust and future proof. I often find myself forgetting how to create, say, a multi select element and needed a sort of cheat sheet that I could look form elements up on.

To this end I sat down and created a list of all of the Drupal form elements and packaged them into a module so that when the path 'form_elements' is loaded a very large form with lots of elements will be rendered. There is even a tabledrag form component in there, which is used quite a bit within the Drupal administration pages.

Apache HTTP Logo

Localhost Apache 2 Server Warning On Ubuntu 11

19th September 2011 - 2 minutes read time

I was recently setting up a localhost environment with Ubuntu 11 and after adding all of my needed VirtualVost directives I found that I could start/restart the server but that I found the following error when trying to start the server.

  1. [email protected]:/etc/apache2/sites-available$ sudo apache2ctl -k start
  2. apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

To fix the problem you needed to add a simple directive to the Apache httpd.conf file. In order to access this file you'll need be have admin access, so open up a terminal window and type the following command.

PHP Logo

Desaturate Images With PHP

6th September 2011 - 5 minutes read time

To desaturate an image means to remove all non-greyscale colours from it, essentially creating a black and white version. To do this you can use the function imagecopymergegray(), which is part of the GD image library. This function is a little difficult to figure out, but what is does is sample one image into another and optionally changing the amount of colours that are kept during the sampling process. The function can be made to sample just a section of the image, or the whole thing. The parameters of the function are as follows.

Drupal Logo

Remove Input Formats Help In Drupal 6

30th August 2011 - 2 minutes read time

The input format help text is a good way of telling your users about the sort of content that they can enter into any text area. For some users, however, they can get in the way a little and even cause confusion, especially when WYISYG editors are used as much of the help text will be quite useless to most users.

The input format section is controlled by the Filter module, which is built into Drupal core, and it comes with a couple of handy hooks that allow control over this section. The filter tips section is split into two parts, the actual filter tips text itself and the more info link below the tips. If you want to remove these then just pop the following into your theme template.php file and change the function names accordingly.

Drupal Logo

Drupal 7: Login Destination Based On User Role

19th August 2011 - 3 minutes read time

The Login Destination module is a neat little module that allows site admins to customize where the user will be sent to when they login. It provides a few of different ways of customizing, including a PHP snippet box that allows fine grained control.

What I needed to do on a recent project was to change the login destination for a single user role, but redirect everyone else to their user profile page. This required the use of the PHP snippet box. In order to get access to the current user object I had to include it into the scope of the PHP snippet code by using the following.

PHP Logo

Getting Started With Xdebug And Netbeans 7 On Windows

16th August 2011 - 16 minutes read time

Note: This article assumes that you have a working Apache/PHP environment running with the latest major version of Netbeans (current 7) installed.

Xdebug is a brilliant PHP extension that provides both debugging and profiling tools. From a basic install it will vastly improve the quality of the error messages but it can also be made to interactively debug scripts using a number of different IDE's. It can also be used as a code profiling tool, but I won't be going into that in this post as that is a little beyond the scope of what I will be talking about.

Installation

If you are using XAMMP to host your Apache/PHP environment then you can skip the following step. Xdebug is actually bundled with XAMMP so you just need to enable it by going into your php.ini file and uncommenting the options you need.

Using The Zend Framework FlashMessenger

14th August 2011 - 6 minutes read time

The FlashMessenger in Zend Framework has a bit of an odd name as it has nothing to do with Adobe Flash at all. It is a controller action helper defined in the class Zend_Controller_Action_Helper_FlashMessenger, which is used to store and retrive messages that are temporarily stored in the user's session. This is useful if you want to provide form validation and redirection at the same time as you can print out messages after the page has been loaded. If you are familiar with Drupal then this class acts in the same kind of way as the drupal_set_messages() function.

Because FlashMessenger is an action helper it can be initialized in a number of different ways, however, using the _helper property (the helper broker) of the controller is probably the easiest way. The FlashMessenger can be retrived through the helper broker in the following ways:

PHP Logo

PHPUnit Skeleton Classes

25th July 2011 - 7 minutes read time

If you create classes in PHP then you should be unit testing them as much as you can. Setting up unit testing classes for your code can be time consuming and involve a bunch of copying and pasting. Thankfully, PHPUnit comes with a couple of helper functions that allow the creation of unit testing classes automatically, which can save a bit of copying and pasting.

As an example for this post I will use the following Spider class, which is part of some code I am working on at the moment to create a simple site spider in PHP.

Linux Logo

Installing A Realtek Wireless Card On OpenSuSE Linux 11

21st July 2011 - 4 minutes read time

I've been using my Medion Akoya E1222 netbook for about a year now and I still think it's an awesome little machine. Recently, I decided to swap from Ubuntu to another Linux distro and have been experimenting with Fedora, JoliOS, PuppyLinux before finally going for OpenSuSE. The only problem I had was figuring out how to get the wireless card working.

I had a little bit of trouble tracking down this information, so I thought I would put it here both for future reference and for anyone else looking for the same information. This is mainly specific for my netbook and particular distribution, but it might help others with the same sort of problems.

The first thing you need to do is find out if your system can actually see the wireless card. This can be done using the lspci command, which in my version of SuSE needed to be called directly from its location in the sbin directory.