drupal_form_submit

  1. drupal
    1. drupal7
Versionen
drupal7 drupal_form_submit($form_id, &$form_state)

Retrieves a form using a form_id, populates it with $form_state['values'], processes it, and returns any validation errors encountered. This function is the programmatic counterpart to drupal_get_form().

Übergabeparameter

$form_id The unique string identifying the desired form. If a function with that name exists, it is called to build the form array. Modules that need to generate the same form (or very similar forms) using different $form_ids can implement hook_forms(), which maps different $form_id values to the proper form constructor function. Examples may be found in node_forms(), search_forms(), and user_forms().

$form_state A keyed array containing the current state of the form. Most important is the $form_state['values'] collection, a tree of data used to simulate the incoming $_POST information from a user's form submission.

... Any additional arguments are passed on to the functions called by drupal_form_submit(), including the unique form constructor function. For example, the node_edit form requires that a node object be passed in here when it is called. For example:

// register a new user $form_state = array(); $form_state['values']['name'] = 'robo-user'; $form_state['values']['mail'] = 'robouser@example.com'; $form_state['values']['pass'] = 'password'; $form_state['values']['op'] = t('Create new account'); drupal_form_submit('user_register', $form_state);

// Create a new node $form_state = array(); module_load_include('inc', 'node', 'node.pages'); $node = array('type' => 'story'); $form_state['values']['title'] = 'My node'; $form_state['values']['body'] = 'This is the body text!'; $form_state['values']['name'] = 'robo-user'; $form_state['values']['op'] = t('Save'); drupal_form_submit('story_node_form', $form_state, (object)$node);

Verwandte Themen

▾ 2 functions call drupal_form_submit()

aggregator_form_opml_submit in modules/aggregator/aggregator.admin.inc
Process aggregator_form_opml form submissions.
form_test_batch_callback in modules/simpletest/tests/form_test.module
Submits form_test_mock_form using drupal_form_submit using the given $value.

Code

includes/form.inc, line 367

<?php
function drupal_form_submit($form_id, &$form_state) {
  if (!isset($form_state['args'])) {
    $args = func_get_args();
    array_shift($args);
    array_shift($args);
    $form_state['args'] = $args;
  }

  $form = drupal_retrieve_form($form_id, $form_state);
  $form_state['input'] = $form_state['values'];
  $form_state['programmed'] = TRUE;
  // Merge in default values.
  $form_state += form_state_defaults();

  drupal_prepare_form($form_id, $form, $form_state);
  drupal_process_form($form_id, $form, $form_state);
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen