欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Drupal7 form表單二次開(kāi)發(fā)要點(diǎn)與實(shí)例

 更新時(shí)間:2014年03月02日 15:00:55   作者:  
這篇文章主要介紹了Drupal7 form表單二次開(kāi)發(fā)要點(diǎn)與實(shí)例,解決了經(jīng)常使用的Form表單提交后跳轉(zhuǎn)問(wèn)題,需要的朋友可以參考下

請(qǐng)記得收藏此文,在你進(jìn)行Drupal 7 custom module時(shí),經(jīng)常會(huì)用到的form 表單的跳轉(zhuǎn)或重載。

主要匯總?cè)齻€(gè)要點(diǎn):

1.頁(yè)面提交后,經(jīng)過(guò)#submit處理后,需要redirect 跳轉(zhuǎn)到另外一個(gè)頁(yè)面。
2.url路徑中存在destination參數(shù)時(shí),頁(yè)面直接跳轉(zhuǎn)到destination所指的url,無(wú)法控制的問(wèn)題。
3.form表單如何實(shí)現(xiàn)multiple steps forms 多個(gè)步驟,或者表單提交后,如何在表單獲取到提交上來(lái)的值。

一、Form 表單 redirect(跳轉(zhuǎn))到另外一個(gè)頁(yè)面

$form_state['redirect'] 的值可以是字符串或者數(shù)組,值通過(guò)url后,生成跳轉(zhuǎn)地址。

復(fù)制代碼 代碼如下:
$form_state['redirect'] = array(
  'node/123',
  array(
    'query' => array(
      'foo' => 'bar',
    ),
    'fragment' => 'baz',
}
//頁(yè)面將會(huì)跳轉(zhuǎn)到 node/123?foo=bar#baz

復(fù)制代碼 代碼如下:
$form_state['redirect'] = 'node/123'
//頁(yè)面將會(huì)跳轉(zhuǎn)到 node/123


如果不指定$form_state['redirect'] 的值,默認(rèn)跳轉(zhuǎn)到當(dāng)前頁(yè)面。drupal_goto(current_path(), array(‘query' => drupal_get_query_parameters())); API中是這樣執(zhí)行的。

二、Form 表單 destination(目的地)被指定時(shí)也可以改變跳轉(zhuǎn)的地址

在drupal_goto 函數(shù)中,你可以看到如果url路徑中存在destination參數(shù),頁(yè)面直接就到destination所指向的鏈接,導(dǎo)致某些表單下的多個(gè)按鈕提交后,本應(yīng)redirect 跳轉(zhuǎn)的頁(yè)面也不盡不同。

于是在form的#submit 函數(shù)中,某些操作時(shí)可以直接刪除掉destination。

復(fù)制代碼 代碼如下:
if (isset($_GET['destination'])) {
  $form_state['redirect'] = array('next_step_page_url', array('query' => drupal_get_destination()));
  unset($_GET['destination']);
}

我采取的方法是,重新定義一個(gè)url并繼續(xù)傳遞destination,但是將$_GET中的destination刪除掉。但是一般還是會(huì)經(jīng)常用到destination這個(gè)目的地的跳轉(zhuǎn)。

三、Form 表單 實(shí)現(xiàn)multiple steps多個(gè)步驟,F(xiàn)orm表單重載,獲取Form提交的值

這些問(wèn)題其實(shí)歸根到底都是一個(gè)意思,就是讓表單繼續(xù)提交下去。而不是刷新頁(yè)面。只需在form 表單的 #submit 函數(shù)中 執(zhí)行以下代碼:

復(fù)制代碼 代碼如下:
if ($form_state['values']['op'] == t("Next Step")) {
  $form_state['rebuild'] = TRUE;
  $form_state['storage']['users'] = $form_state['values']['users'];
}

在form的define定義中即可獲取到$form_state['storage']['users']這個(gè)值。

參考Drupal7 相關(guān)API函數(shù):

drupal_redirect_form
drupal_goto
drupal_get_destination

相關(guān)文章

最新評(píng)論