SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * Implements hook_block_info() - defines the block | |
| 5 | */ | |
| 6 | function mvp_form_test_block_info() {
| |
| 7 | $blocks = array( | |
| 8 | 'mvp_form_test_test_block' => array( | |
| 9 | 'info' => 'Test Form', | |
| 10 | 'cache' => DRUPAL_CACHE_GLOBAL, | |
| 11 | 'properties' => array( | |
| 12 | 'administrative' => true, | |
| 13 | ), | |
| 14 | ), | |
| 15 | ); | |
| 16 | return $blocks; | |
| 17 | } | |
| 18 | ||
| 19 | /** | |
| 20 | * Implements hook_block_view() - returns the form | |
| 21 | */ | |
| 22 | function mvp_form_test_block_view($delta='') {
| |
| 23 | if ($delta != 'mvp_form_test_test_block') | |
| 24 | return array(); | |
| 25 | ||
| 26 | return array( | |
| 27 | 'title' => 'Test Block', | |
| 28 | 'content' => drupal_get_form('mvp_form_test_test_form'),
| |
| 29 | ); | |
| 30 | } | |
| 31 | ||
| 32 | /** | |
| 33 | * Form callback - displays simple form with only one field and a submit button | |
| 34 | */ | |
| 35 | function mvp_form_test_test_form($form, &$form_state) {
| |
| 36 | $form = array(); | |
| 37 | $form['sometext'] = array( | |
| 38 | '#type' => 'textfield', | |
| 39 | ); | |
| 40 | $form['button'] = array( | |
| 41 | '#type' => 'submit', | |
| 42 | '#value' => 'Submit', | |
| 43 | ); | |
| 44 | return $form; | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Implements form_submit() - sets a message and a watchdog entry with the value submitted via the form | |
| 49 | */ | |
| 50 | function mvp_form_test_test_form_submit($form, $form_state) {
| |
| 51 | watchdog('mvp_form_test', 'Form submitted with text '.$form_state['values']['sometext']);
| |
| 52 | drupal_set_message('Form submitted with text '.$form_state['values']['sometext']);
| |
| 53 | } | |
| 54 | ||
| 55 | ?> |