Key points and examples of secondary development of Drupal7 form_PHP tutorial

WBOY
Release: 2016-07-13 10:37:01
Original
902 people have browsed it

Please remember to bookmark this article. When you develop Drupal 7 custom module, you will often use form jumps or reloads.

Mainly summarize three key points:

1. After the page is submitted, after #submit processing, you need to redirect to another page.
2. When there is a destination parameter in the url path, the page jumps directly to the url pointed by the destination, which is an uncontrollable problem.
3. How to implement multiple steps forms, or how to get the submitted value in the form after the form is submitted.

1. Form redirect (jump) to another page

The value of $form_state['redirect'] can be a string or an array. After the value passes through the url, a jump address is generated.

Copy code The code is as follows:
$form_state['redirect'] = array(
'node/123',
array(
'query' => array(
'foo' => 'bar',
),
'fragment' => 'baz',
}
//The page will jump to node/123?foo=bar#baz

Copy code The code is as follows:
$form_state['redirect'] = 'node/123'
//The page will Jump to node/123


If the value of $form_state['redirect'] is not specified, it will jump to the current page by default. drupal_goto(current_path(), array('query' => drupal_get_query_parameters())); This is how it is executed in the API.

2. When the Form form destination is specified, the jump address can also be changed

In the drupal_goto function, you can see that if there is a destination parameter in the url path, the page will go directly to the link pointed to by the destination. As a result, after multiple buttons under some forms are submitted, the page that should be redirected will also redirect. Not quite the same.

So in the #submit function of the form, the destination can be deleted directly during certain operations.

Copy code The code is as follows:
if (isset($_GET['destination'])) {
$form_state[' redirect'] = array('next_step_page_url', array('query' => drupal_get_destination()));
unset($_GET['destination']);
}

I take The method is to redefine a url and continue to pass the destination, but delete the destination in $_GET. But generally, the destination jump is often used.

3. Form implements multiple steps, reloads the Form, and obtains the value submitted by the Form

These questions all have the same meaning in the final analysis, which is to allow the form to continue to be submitted. instead of refreshing the page. Just execute the following code in the #submit function of the form:

Copy code The code is as follows:
if ($form_state['values']['op'] == t("Next Step ")) {
$form_state['rebuild'] = TRUE;
$form_state['storage']['users'] = $form_state['values']['users'];
}

The value $form_state['storage']['users'] can be obtained in the form's define definition.

Refer to Drupal7 related API functions:

drupal_redirect_form
drupal_goto
drupal_get_destination

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736823.htmlTechArticlePlease remember to bookmark this article. When you develop Drupal 7 custom module, you will often use the form jump Transfer or reload. Mainly summarize three main points: 1. After the page is submitted, it will be processed by #submit...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!