I am trying to create a module (Drupal 7) which will have the following workflow: 1. User enters data via form (frontend) 2. The data is validated and get stored in database (custom content type e.g. Reservations ) 3. User will receive confirmation e-mail 4. User will be redirected to another page 5. Data will be manipulated by Admin (CRUD functionality)

Ideally, I would create custom content type via GUI e.g. Reservations. And when use the Views module to manipulate the data. Could anyone suggest any tutorial or explanation about how should I proceed Pls. Note that already played with Webform module and found that I prefer to do it via custom module and Form API

Thank you in advance


You can do it via drupal's form API, First create your content type

1.Create a module (http://drupal.org/node/361112)

2.Create menu callback

function form_example_menu() {
  $items = array();
  $items['examples/form_example/tutorial'] = array(
    'title' => 'Form Tutorial',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_1'),
    'access callback' => TRUE,
    'description' => 'A set of ten tutorials',
    'type' => MENU_NORMAL_ITEM,

3.Use form api create form with necessary fields

function form_example_tutorial_1($form, &$form_state) {
  //your fields goes here
   $form['name']['first'] = array(
     '#type' => 'textfield',
     '#title' => t('First name'),
     '#required' => TRUE,
     '#default_value' => "First name",
     '#description' => "Please enter your first name.",
     '#size' => 20,
     '#maxlength' => 20,


4.Add necessary validation

function form_example_tutorial_1_validate($form, &$form_state) {
  //your validation goes here

5.Add form submission codes

function form_example_tutorial_1_submit($form, &$form_state) {
  //here you can process your data, in your case you want save it to a content type. so you can use node_save here
  $node = new stdClass();
  $node->title = $new_node['title'];
  $node->body['und'][0]['value'] = $new_node['body'];
  $node->type = 'article';
  //include all necessary fields

  //after success full save you can  write code for confirmation e-mail and redirection page

6.As you have saved data to a content type, You can create a view with all required details, with edit delete functionality

If you have any doubt in module development and implementing form api you can get examples on this page http://drupal.org/project/examples

hope this may helps you

  • Currently I am trying to understand if it is appropriate to create the Custom Content Type via GUI or to create seperate Table to store the necessary data. And if I go with 2nd solution can I use Views to show data. By the way, this is very extensive answer ... thanks. – Jim Oct 1 '12 at 11:24
  • It is better to 'create Content Type via GUI' method, so that you will get all details in view. If you go for custom db table, in order to get support in views you have to write custom codes using views hook – Anoop Joseph Oct 1 '12 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.