drupal_prepare_form 大致是如何工作的 ?

來源:互聯網
上載者:User

標籤:

函數原型是這樣的

function drupal_prepare_form($form_id, &$form, &$form_state) {//---}

1 初始化一些變數

  $form[‘#type‘] = ‘form‘;  $form_state[‘programmed‘] = isset($form_state[‘programmed‘]) ? $form_state[‘programmed‘] : FALSE;        // Fix the form method, if it is ‘get‘ in $form_state, but not in $form.  if ($form_state[‘method‘] == ‘get‘ && !isset($form[‘#method‘])) {    $form[‘#method‘] = ‘get‘;  }

2  form build id

  if (!isset($form[‘#build_id‘])) {    $form[‘#build_id‘] = ‘form-‘ . drupal_random_key();  }  $form[‘form_build_id‘] = array(    ‘#type‘ => ‘hidden‘,    ‘#value‘ => $form[‘#build_id‘],    ‘#id‘ => $form[‘#build_id‘],    ‘#name‘ => ‘form_build_id‘,    // Form processing and validation requires this value, so ensure the    // submitted form value appears literally, regardless of custom #tree    // and #parents being set elsewhere.    ‘#parents‘ => array(‘form_build_id‘),  );

3 form token

$form[‘form_token‘] = array(        ‘#id‘ => drupal_html_id(‘edit-‘ . $form_id . ‘-form-token‘),        ‘#type‘ => ‘token‘,        ‘#default_value‘ => drupal_get_token($form[‘#token‘]),        // Form processing and validation requires this value, so ensure the        // submitted form value appears literally, regardless of custom #tree        // and #parents being set elsewhere.        ‘#parents‘ => array(‘form_token‘),      );

4 form id

  if (isset($form_id)) {    $form[‘form_id‘] = array(      ‘#type‘ => ‘hidden‘,      ‘#value‘ => $form_id,      ‘#id‘ => drupal_html_id("edit-$form_id"),      // Form processing and validation requires this value, so ensure the      // submitted form value appears literally, regardless of custom #tree      // and #parents being set elsewhere.      ‘#parents‘ => array(‘form_id‘),    );  }

5 form[‘#id‘]

 if (!isset($form[‘#id‘])) {    $form[‘#id‘] = drupal_html_id($form_id);  }

6 action  + method   +  theme-wrapper

$form += element_info(‘form‘);

7 tree parents

$form += element_info(‘form‘);

8 validate | submit

 if (function_exists($form_id . ‘_validate‘)) {      $form[‘#validate‘][] = $form_id . ‘_validate‘;    }

9 $form[‘#theme‘]

if (!isset($form[‘#theme‘])) {    $form[‘#theme‘] = array($form_id);    if (isset($form_state[‘build_info‘][‘base_form_id‘])) {      $form[‘#theme‘][] = $form_state[‘build_info‘][‘base_form_id‘];    }  }

10 為hook_form_alter做準備

  $hooks[] = ‘form_‘ . $form_id;  drupal_alter($hooks, $form, $form_state, $form_id);

 

drupal_prepare_form 大致是如何工作的 ?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.