pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

drupal private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Steven Merrill on Sun 14 Sep 22:32
report abuse | View followups from Steven Merrill | download | new post

  1. <?php
  2. // $Id: page_example.module,v 1.13 2007/10/17 19:38:36 litwol Exp $
  3.  
  4. /**
  5.  * @file
  6.  * This is an example outlining how a module can be used to display a
  7.  * custom page at a given URL.
  8.  */
  9.  
  10. /**
  11.  * Implementation of hook_menu().
  12.  */
  13. function page_example_menu() {
  14.   // This is the minimum information you can provide for a menu item.
  15.   $items['foo'] = array(
  16.     'title' => 'Foo',
  17.     'page callback' => 'drupal_get_form',
  18.     'page arguments' => array('page_example_foorm'),    
  19.     'access arguments' => array(),
  20.   );
  21.  
  22.   return $items;
  23. }
  24.  
  25. /**
  26.  * A page callback.
  27.  */
  28. function page_example_foorm() {
  29.   $form = array();
  30.   $form['foo'] = array(
  31.     '#type' => 'textfield',
  32.     '#title' => t('foo'),
  33.     '#default_value' => variable_get('page_example_foo', 'not-bar'),
  34.     '#size' => 60,
  35.     '#maxlength' => 64,
  36.     '#description' => t('baz'),
  37.     '#weight' => 10,
  38.   );
  39.  
  40.   $form['bar'] = array(
  41.     '#type' => 'textfield',
  42.     '#title' => t('bar'),
  43.     '#default_value' => t('barbazthing'),
  44.     '#size' => 60,
  45.     '#maxlength' => 64,
  46.     '#description' => t('foobar'),
  47.     '#weight' => 12,
  48.   );
  49.  
  50.   $form['submit'] = array(
  51.     '#type' => 'submit',
  52.     '#value' => t('Save'),
  53.     '#weight' => 15,
  54.   );
  55.  
  56.   return $form;
  57. }
  58.  
  59. /**
  60.  * Validation function for page_example_foorm()
  61.  */
  62. function page_example_foorm_validate($form, &$form_state) {
  63.   if ($form_state['values']['foo'] == 'bar') {
  64.     form_set_error('foo', t('There was a problem. Foo was bar.'));
  65.   }
  66. }
  67.  
  68. /**
  69.  * Submit function for page_example_foorm()
  70.  */
  71. function page_example_foorm_submit($form, &$form_state) {
  72.   variable_set('page_example_foo', $form_state['values']['foo']);
  73.   drupal_set_message(t('Yay! The value of foo was set to @value!',
  74.     array('@value' => $form_state['values']['foo'])));
  75. }

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.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post