How To Create a Form Callback with Drupal 7 – Part 1


Drupal Logo

INTRODUCTION

Working with Drupal for a couple years, I wanted to create a form with a callback. I admit there are one or two methods to create a Drupal 7 form. I created the form in the module location in the sites/all/modules/custom/{modname}. In this series, will step though a process to create this form. The form submits data into the database and return a message all on the same page without a page reload.

Required Knowledge: Drupal 7, PHP, MySQL, Coding Knowledge, etc…

If you are a new comer to Drupal Module Creation, I will try to cover as much as possible in my series. I will try not to make this too boring for the more advanced people.

CREATE THE MODULE

Modules created are self-recognized by two files that must be in the folder of your newly created custom module.
1. The .module file. Example: signup.module
2. The .info file Example: signup.info

The .module file is where all the custom code is written and can be left empty for this example.

The .info file needs a couple of things to become visible on the Drupal Module Page in the admin area.

The most basic .info file needs some variables assigned, the basic variables are name, description, dependencies array, core and package.

  1. Create the folder named sample all lower case in this location. sites/all/modules/custom/sample
  2. Create the files below.

sample.module

// Intentionally left blank for sample module
// However the file needs to exist in the folder.

sample.info

name = Sample Module
description = this is a newly created sample module
dependencies[] = mods,views
core = 7.x
package = Sample Module For Example Purposes

After typing or copy/pasting all this into the sample.info file and creating a sample.module file you will have this module listed on Drupal Module page.

Before we dive to far into the nuts and bolts of the form creation, beginners will need to understand the basics of Drupal 7 module creation. This watered down version hopefully will help. Use Google to find additional help if needed. I’ll try recording a video soon. The next part of this series will be basics of form creation.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s