Archive for the ‘Drupal’ category

How to Customize the Syndicate Feed Icon Block in Drupal

August 25th, 2009

For a recent project I needed to customize the feed icon in the Drupal theme I was creating. This wasn’t as straight forward as I thought it would be. Being the drupal newbie that I am I went looking for it in the core templates and suggestions page only to come empty handed.

Previously I found the solution to theming a search form by using the search-block-form.tpl.php template file and thought there would be one for the feed icon too. I found the solution to this in the function reference in the form of a theme hook.

theme_feed_icon($url, $title)

This function is internally called by drupal to generate the feed icon in the Syndicate block. Our Job is to override this function.

Customizing the feed icon

We cannot redefine the same function in our theme so we must define a phptemplate function to override the default implementation.

function phptemplate_feed_icon($url,$title)

What It Must Do?

This function must return the code of the feed icon. Therefore instead of using a image, you may also use a text link as well as hard code a few options such as Subscribe via Twitter and E-Mail.

Therefore, to use your own subscribe by RSS icon, you may use a function similar to the following:

function phptemplate_feed_icon($url,$title)
{
	global $base_path;
	$path = path_to_theme();
 $feed_icon = '<a href=" '. check_url($url).'" class="feed-icon"><img src="'. $path.'/images/rss-header.png" /></a>';
        return $feed_icon;
}

This function is very simple . It just returns a image which is linked to the $url parameter of the function. This function is to be placed in the template.php file.

Summary

  • Syndicate feed icon is customized using the theme_feed_icon template function.
  • We use phptemplate_feed_icon($url,$title)  in our function to customize the syndicate feed icon block.
  • The function should return the code of the syndicate feed block. This code may also include links to other services such as twitter and subscribing by e-mail.
  • The function should be placed in your template.php file.

How To Create Custom Forms Using Drupal In 4 Easy Steps

August 10th, 2009

Until now the only way to create your own forms was by creating a plugin or hack the core of the content management system. Drupal however has a community created module that allows anyone to create a form on a website. The form can either send the entered data to your email address or save it in a database or both. There are a number of reasons why you will need to create a form. Here are some examples:

  • Create a Bug Report form for your buyers or users for your software
  • Register for an upcoming event.
  • Submit content to the website
  • Add a help desk to your drupal website

When the form is filled out, we may want the entries to be

  • Sent to us by e-mail
  • Save to the database

One can create a form in drupal without any coding knowledge. This tutorial shows how to create a registration form using drupal. In this tutorial we will be creating a academic research paper registration form. The form will take the name, number of participants, the event they want to attend, the name of their college, number of participants, brief abstract, and the files that show the full paper of the event.

I have chosen this form because this demonstrates the many commonly needed form field elements – one line text fields, multiple selection fields, radio buttons, multi line text areas and file upload fields. I assume that you already have a installation of drupal somewhere. If not, read my earlier article on the steps to install drupal on your shared hosting server. Our form will have the following fields

Field Name Field Type
Name Textfield
E-Mail Textfield
Title of Paper Textfield
College Name Textfield
Brief abstract TextArea
Number of participants Select Field
Research Paper as Word Document File field

Step 1: Download webform module from drupal.org.

Webform is the module we are going to use to create forms. This module adds a new content type of “webform” which will be our form. The webform module can be downloaded here..

Step 2: Enable the webform module.

Upload the modules files to the [website root]/sites/all/modules directory. The modules directory may need to be created if it doesn’t already exist. To learn how to install drupal modules, read my artilce on the same topic here.

1
Click to enlarge
2
Click to enlarge

Step 3: Create New Form

Enter the menu settings for the form where you can specify in which menu you want a link to this form to appear along with its link text. Then specify the form name, public description that appears above the form, and the text to show after the form has been filled.

Create new form

Click to enlarge

Next specify to which e-mail address the content of this form is to be sent along with the subject, from address that is seen in the e-mail received. If the form will be used by registered users you can also specify how many times a user is allowed to register the form.

Form email settings fields

Click to enlarge

Finally specify the text that is on the button such as “Register” or “Save” or “Submit”. Under comment settings, make sure you disable the form as it would look awkward and confusing to have a comment field below the registration form.

Create New Web Form

create a new form in drupal

Click on Create Content link on the navigation menu click on Web Form

Enter the form’s information such as name and the email address where the form’s information is to be sent when it is submitted by the user. It is also possible to customize the validation of the form.

4

Click on image to enlarge

Step 4: Create the form fields

When you click save, you will now see a empty list. You can now start adding form fields to the form. Enter the appropriate field name in the name field, select the appropriate type in the type column, specify it it is an email and if this field takes an email address and click Add.

7

Click to see enlarge

Having created the form’s page, now you can add its form fields

In the resulting form, enter the name, default value if any, the description to be given for the and optionally the width, maxlength, label to be placed before the textbox and after the textbox. There is a section for advanced settings if you want to customize the field further.

8

Click to enlarge

Enter the name, select the type of field, specify if the field is mandatory and specify if this field is an email address.

4-5

Create form field form. Enter name, brief description, a default value if applicable.

Do the same for the name, email, title and college name fields.

The participants field is given a limit of 1-3 participants so we should make it a drop down selection box allowing the user to select the number of participants. For the number of participants field, select the field as the type. Once you click Add, you will see a textarea labeled ‘Options’. Enter the options one in each line.

Enter the options you want to display in the drop down field. Make sure you check the Listbox check box to display the options as a select item instead of a set of radio boxes.

Enter the options you want to display in the drop down field. Make sure you check the

Listbox check box to display the options as a select item instead of a set of radio boxes.

In this case we are going to enter 1,2 and 3 each in its own line.

For the research paper files field we choose a field of type file and click Add.

Selection of acceptable file types for upload

Click to enlarge

Now we’re presented we have an option to specify the acceptable file types of this field. I have selected doc, pdf, odf, html, rar, bz2, gz and zip and specified a upload limit of 800kb. Save the form field.

Now click publish to see the form. When you fill the form out and click submit, sends the following e-mail to the e-mail address we specified in step 3.

E-Mail received from the form created in drupal

Closing Notes

Using the webform module anyone can create a webform. Even non-programmers can create forms for their website using this method.

Drupal Module: Twitter Block – Add Your Twitter Feed To Your Drupal Website

June 23rd, 2009
Update: Twitter has disabled the API to which this module was originally interfaced. Please download the new version that works using RSS feeds here. You do NOT have to provide your twitter password to show your tweets in the block.

Why don’t you show how relevant you are to your site visitors and get more followers on twitter? Once they start following you, you can start pointing them to your website again and again now that you have their attention.

Unfortunately there isn’t a simple way to create this block from the existing drupal modules. The procedure to create a Twitter block is very convoluted using Views and what not.

twitterblock

But first, a little rant. It seems like a lot of developers are more focused on being ‘standards complaint’ (politically correct) than create easy to use software as if they create software for other developers.

“Oh! let’s not rehash the code here, that’s not good core re-use. Let’s ask users of our module to download and install 10 other modules on which we will base this module!”

This block is installed through the module (download below).

The block is highly customizable. Check out the options you have in the administrator’s interface.

This interface is found in Administer > Sites Building > Blocks > Twitter Block [configure]

configuration

The blocks can be theme using css as each element is enclosed in a <div> of appropriate name.

Download

Click here to download the module.

Installation Steps

1. Install the Module: Just place the module in the modules directory of your drupal site or sites/all/modules/ directory if you have multiple installations. Log in as administrator and go to Site Building > Modules. Scroll to the bottom and find “Other” package. Expand it, check the TwitterBlock one and click Save Changes.

2. Place The Block In A Region: Now go to Administer > Site Building > Blocks. At the bottom of the list you will find Twitter Block. Drag it to the required region and click Save Changes.

3. Enter Username/Password: Once you click save, you will still not see the block, you must enter the username and password. So click on ‘configure’ next to Twitter block and enter your username and password. Choose a appropriate update frequency and click Save.

You’re all done. Your module should be working now. Leave a comment on this post regarding bug fixes and other issues.

License

This module is provided under the GPL license. Read the full version here.

How To Install A Drupal Module

June 8th, 2009

This article will show you how to install a module in drupal.

Drupal modules are pieces of software that are added to the drupal cms software to add some features. For example a contact form can be added using drupal modules. This feature doesn’t come built into drupal by default.

Drupal modules can be downloaded from the drupal moule repository. Click here to go to the module repository.

Once you dowload a module do the following steps to install it.

1. Extract the archive to a folder on your computer. We are going to upload the directory that has the module files (*.info, *.module *.install) in it.

2. In the directory where you installed drupal, under sites/all/ create a folder called modules.

3. Upload the folder extracted in step 1 to this directory.

4. Log into your drupal installation as an administrator. Go to Administer > Site Building > Modules

5. The module must be listed in the resulting page. Click on the check box near the name of the module and click save configuration.

That’s it!

How To Install Drupal On Your Shared Hosting Server.

May 23rd, 2009

Drupal is the best content management system I have ever come across. It has all the features necessary to build any website. Drupal can save you thousands of dollars in development costs by simplifying the development of complex applications and portal websites. The drupal community has created thousands of plugins which can be configured to achieve any functionality desired in a content management system. This article will show you how to install Drupal on your shared hosting server. This article will show you how to install drupal in a shared hosting server.

» Read more: How To Install Drupal On Your Shared Hosting Server.