drupal_get_form

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/form.inc, строка 48

Версии
5 – 6
drupal_get_form($form_id)

Запрашивает форму из функции создания формы, возвращает её для обработки, передаёт значения формы в то место, где они требуются. В сценариях, в которых используется многошаговая структура использования форм, это позволяет управлять правильностью передачи соответствующих данных с предыдущего шага работы сценария, делать необходимый следующий шаг для отображения результата.

Параметры

$form_id - уникальная строка, идентифицирующая форму. Если существует функция с таким же именем, она вызывается для формирования соответствующей формы. Модули, которые генерируют несколько одинаковых ( или очень похожих) форм, используя разные $form_id, могут реализовать функцию hook_forms(), которая связывает разные значения $form_id с соответствующей функцией-конструктором формы. Примеры можно найти в node_forms(), search_forms() и user_forms().

... Все дополнительные аргументы передаются функции-конструктору формы.

Возвращаемое значение

HTML-код формы.

Связанные темы

▾ 39 функции вызывают drupal_get_form()

book_admin in modules/book/book.module
Menu callback; displays the book administration page.
comment_admin in modules/comment/comment.module
Коллбэк меню; отображает список комментариев для администрирования.
comment_delete in modules/comment/comment.module
Коллбек меню; Подтверждение удаления комментария.
comment_form_box in modules/comment/comment.module
comment_render in modules/comment/comment.module
Отображает комментарии.
contact_site_page in modules/contact/contact.module
Site-wide contact page
contact_user_page in modules/contact/contact.module
Страница персональных контактов.
example_profile_tasks in ./example.profile
Perform any final installation tasks for this profile.
forum_form_main in modules/forum/forum.module
install_change_settings in ./install.php
Configure and rewrite settings.php.
install_select_locale in ./install.php
Find all .po files for the current profile and allow admin to select which to use.
install_select_profile in ./install.php
Find all .profile files and allow admin to select which to install.
locale_admin_import in modules/locale/locale.module
Page handler for the translation import screen
locale_admin_manage in modules/locale/locale.module
Page handler for the language management screen.
locale_admin_string_delete_page in modules/locale/locale.module
String deletion confirmation page.
locale_string_search in modules/locale/locale.module
Page handler for the string search.
node_add in modules/node/node.module
Present a node submission form or a set of links to such forms.
node_admin_content in modules/node/node.module
Menu callback: content administration.
node_admin_search in modules/node/node.module
node_page_edit in modules/node/node.module
Menu callback; presents the node editing form, or redirects to delete confirmation.
node_revision_delete in modules/node/node.module
Delete the revision with specified revision number. A 'delete revision' nodeapi event is invoked when a revision is deleted.
node_revision_revert in modules/node/node.module
Revert to the revision with the specified revision number. A node and nodeapi 'update' event is triggered (via the node_save() call) when a revision is reverted.
phptemplate_page in themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_page function to be passed into a pluggable template engine. Uses the arg() function to generate a series of page template files suggestions based on the current path. If none are found, the default page.tpl.php...
poll_view in modules/poll/poll.module
Реализация hook_view().
search_block in modules/search/search.module
Реализация hook_block().
search_view in modules/search/search.module
Menu callback; presents the search form and/or search results.
taxonomy_admin_term_edit in modules/taxonomy/taxonomy.module
Page to edit a vocabulary term.
taxonomy_admin_vocabulary_edit in modules/taxonomy/taxonomy.module
Page to edit a vocabulary.
theme_poll_results in modules/poll/poll.module
update_selection_page in ./update.php
user_admin in modules/user/user.module
user_admin_access_add in modules/user/user.module
Menu callback: add an access rule
user_admin_access_check in modules/user/user.module
Menu callback: check an access rule
user_admin_access_edit in modules/user/user.module
Menu callback: edit an access rule
user_block in modules/user/user.module
Реализация hook_block().
user_edit in modules/user/user.module
watchdog_overview in modules/watchdog/watchdog.module
Menu callback; displays a listing of log messages.
_locale_admin_export_screen in includes/locale.inc
User interface for the translation export screen
_locale_admin_manage_add_screen in includes/locale.inc
User interface for the language addition screen.

Код

<?php
function drupal_get_form($form_id) {
  // In multi-step form scenarios, the incoming $_POST values are not
  // necessarily intended for the current form. We need to build
  // a copy of the previously built form for validation and processing,
  // then go on to the one that was requested if everything works.

  $form_build_id = md5(mt_rand());
  if (isset($_POST['form_build_id']) && isset($_SESSION['form'][$_POST['form_build_id']]['args']) && $_POST['form_id'] == $form_id) {
    // There's a previously stored multi-step form. We should handle
    // IT first.
    $stored = TRUE;
    $args = $_SESSION['form'][$_POST['form_build_id']]['args'];
    $form = call_user_func_array('drupal_retrieve_form', $args);
    $form['#build_id'] = $_POST['form_build_id'];
  }
  else {
    // We're coming in fresh; build things as they would be. If the
    // form's #multistep flag is set, store the build parameters so
    // the same form can be reconstituted for validation.
    $args = func_get_args();
    $form = call_user_func_array('drupal_retrieve_form', $args);
    if (isset($form['#multistep']) && $form['#multistep']) {
      // Clean up old multistep form session data.
      _drupal_clean_form_sessions();
      $_SESSION['form'][$form_build_id] = array('timestamp' => time(), 'args' => $args);
      $form['#build_id'] = $form_build_id;
    }
    $stored = FALSE;
  }

  // Process the form, submit it, and store any errors if necessary.
  drupal_process_form($args[0], $form);

  if ($stored && !form_get_errors()) {
    // If it's a stored form and there were no errors, we processed the
    // stored form successfully. Now we need to build the form that was
    // actually requested. We always pass in the current $_POST values
    // to the builder function, as values from one stage of a multistep
    // form can determine how subsequent steps are displayed.
    $args = func_get_args();
    $args[] = $_POST;
    $form = call_user_func_array('drupal_retrieve_form', $args);
    unset($_SESSION['form'][$_POST['form_build_id']]);
    if (isset($form['#multistep']) && $form['#multistep']) {
      $_SESSION['form'][$form_build_id] = array('timestamp' => time(), 'args' => $args);
      $form['#build_id'] = $form_build_id;
    }
    drupal_prepare_form($args[0], $form);
  }

  return drupal_render_form($args[0], $form);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему