Tuesday, March 8, 2011

Simple Form Example Drupal 7 with Submit

Simple Form Example Drupal Below is the folder structure

















deductibe.info

;$Id$
name = CalculateDeductible
description = CalculateDeductible
package = Drupal 7 Development
core = 7.x
files[] = deductible.module
;dependencies[] = autoload
php = 5.2
 


deductible.module

<?php
//;$Id$

function deductible_menu(){
$items['deductible/calculate']=array(
'title'=>'Calculate Deductible',
'page callback'=>'drupal_get_form',
'page arguments'=>array('deductible_simple_form'),
'access arguments' => array('administer user'),
);
return $items;
}

function deductible_simple_form($form,&$form_submit){
      $form['Make'] = array(
        '#type' => 'textfield',
        '#title' => t('Make'),
          '#cols' => 30,
           '#rows' => 1,
      );
        $form['Model'] = array(
        '#type' => 'textfield',
        '#title' => t('Models'),
          '#cols' => 30,
        '#rows' => 1,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
       '#submit' => array('deductible_submit'),
     
      );
      return $form;
}

/**
 * Implementation of hook_perm().
 */
function deductible_perm() {
  return array('use save and edit', 'administer save and edit');
}

function deductible_submit($form, &$form_values){
      watchdog('Deductibe', 'deductible', array(), WATCHDOG_DEBUG);
      $message = 'You have submitted the ' /*. $form_id . ' form which contains the following data:<pre>' . print_r($form_values,true) . '</pre>'*/;
      drupal_set_message(t($message));
    }


----------

Now place the folder under drupalinstallation/site/all/modules 
Enable the module from Modules
Now go to http://localhost/deductible/calculate

Check this link
http://harshal-techapps.blogspot.com/2011/03/create-simple-module-in-drupal-7.html

13 comments:

  1. when i copy code above is not display menu link. I have enable already.

    ReplyDelete
  2. Does not report the entered values.

    ReplyDelete
  3. Try this submit function:

    function deductible_submit($form, &$form_values){
    drupal_set_message(t('The form has been submitted. name="@model @make"',
    array('@model' => $form_values['values']['Model'], '@make' => $form_values['values']['Make'])));
    }

    ReplyDelete
  4. That works! thanks!

    ReplyDelete
  5. AOA
    i am a beginer to drupal.i don't know how to make form and how to insert values into database.i try your code but it doesn't show anything.

    ReplyDelete
  6. Putaness ang jutangkess!

    ReplyDelete
  7. Good demo but more difficulty in this demo

    ReplyDelete
  8. i am a beginer to drupal.i don't know how to make form and how to insert values into database.i try your code but it doesn't show anything.

    ReplyDelete
  9. The code works but I don't see the submissions in the sql database... any thoughts on why i dont see the make and model i submitted show up in sql?

    ReplyDelete
  10. believe that the 'insert' function is missing?

    ReplyDelete