Posted by Steven Merrill on Sun 14 Sep 22:32
report abuse | View followups from Steven Merrill | download | new post
- <?php
- // $Id: page_example.module,v 1.13 2007/10/17 19:38:36 litwol Exp $
- /**
- * @file
- * This is an example outlining how a module can be used to display a
- * custom page at a given URL.
- */
- /**
- * Implementation of hook_menu().
- */
- function page_example_menu() {
- // This is the minimum information you can provide for a menu item.
- 'title' => 'Foo',
- 'page callback' => 'drupal_get_form',
- );
- return $items;
- }
- /**
- * A page callback.
- */
- function page_example_foorm() {
- '#type' => 'textfield',
- '#title' => t('foo'),
- '#default_value' => variable_get('page_example_foo', 'not-bar'),
- '#size' => 60,
- '#maxlength' => 64,
- '#description' => t('baz'),
- '#weight' => 10,
- );
- '#type' => 'textfield',
- '#title' => t('bar'),
- '#default_value' => t('barbazthing'),
- '#size' => 60,
- '#maxlength' => 64,
- '#description' => t('foobar'),
- '#weight' => 12,
- );
- '#type' => 'submit',
- '#value' => t('Save'),
- '#weight' => 15,
- );
- return $form;
- }
- /**
- * Validation function for page_example_foorm()
- */
- function page_example_foorm_validate($form, &$form_state) {
- if ($form_state['values']['foo'] == 'bar') {
- form_set_error('foo', t('There was a problem. Foo was bar.'));
- }
- }
- /**
- * Submit function for page_example_foorm()
- */
- function page_example_foorm_submit($form, &$form_state) {
- variable_set('page_example_foo', $form_state['values']['foo']);
- drupal_set_message(t('Yay! The value of foo was set to @value!',
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.