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
<?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
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
when i copy code above is not display menu link. I have enable already.
ReplyDeleteDoes not report the entered values.
ReplyDeleteTry this submit function:
ReplyDeletefunction 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'])));
}
That works! thanks!
ReplyDeleteAOA
ReplyDeletei 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.
iopugbpç
ReplyDeletePutaness ang jutangkess!
ReplyDeleteMatammmmess ang Pates
Deletejghjhgj
ReplyDeleteGood demo but more difficulty in this demo
ReplyDeletei 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.
ReplyDeleteThe 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?
ReplyDeletebelieve that the 'insert' function is missing?
ReplyDelete