国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊(cè) Drupal7 form表單二次開(kāi)發(fā)要點(diǎn)與實(shí)例

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

Jun 13, 2016 am 09:41 AM

請(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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276