This example module will provide a form where you can enter your name and upon submission will display your name as a message on the following page. It is very basic but will give you a start to making your first module. You can change all instances of the word example to the name of your module. First you need to create a file called example.info:
2 | description = "Example module." |
Next you need the
example.module file:
03 | function example_help( $section ) { |
05 | case 'admin/modules#description' : |
06 | return t( 'This module implements an example form.' ); |
10 | function example_menu( $may_cache ) { |
15 | 'title' => t( 'Example' ), |
16 | 'callback' => 'example_page' , |
18 | 'type' => MENU_CALLBACK |
24 | function example_page() { |
25 | return drupal_get_form( 'example_page_form' ); |
28 | function example_page_form() { |
29 | $form [ 'fullname' ] = array ( |
30 | '#type' => 'textfield' , |
31 | '#title' => t( 'Enter your full name' ), |
33 | $form [ 'submit' ] = array ( |
35 | '#value' => t( 'Save' ), |
40 | function example_page_form_submit( $form_id , $form_values ) { |
41 | $message = 'You have submitted the ' . $form_id . ' form which contains the following data:<pre>' . print_r( $form_values ,true) . '</pre>' ; |
42 | drupal_set_message(t( $message )); |
Now you can enable the module, and visit: