Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function test_menu() {
- $items = array();
- $items['test'] = array(
- 'title' => 'Test',
- 'page callback' => 'test_page_handler',
- 'access callback' => TRUE,
- );
- return $items;
- }
- function test_page_handler() {
- $output = drupal_get_form('test_simple_form');
- return $output;
- }
- function test_simple_form(&$form_state) {
- // If the form has already been built, and we already have the data, don't load it again.
- if (isset($form_state['values']['expensive_data'])) {
- $data = $form_state['values']['expensive_data'];
- }
- else {
- // Otherwise get the data from source.
- $data = very_expensive_data_operation();
- }
- // Store the data
- $form['expensive_data'] = array(
- '#type' => 'value',
- '#value' => $data
- );
- $form['create'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
- return $form;
- }
- function test_simple_form_submit(&$form, &$form_state) {
- // do something
- }
- function very_expensive_data_operation() {
- drupal_set_message('Running VEDO ' . time());
- sleep(1);
- return array(1,2,3,4,5,6,7,8,9);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement