This article mainly introduces the secondary development points and examples of Drupal7form, and solves the problem of jump after submitting a frequently used Form. if you need it, you can refer to Drupal
Remember to add this article to favorites. when you perform the Drupal 7 M module, you will often use the form jump or overload.
Three key points are summarized:
1. after the page is submitted and processed by # submit, redirect is required to jump to another page.
2. if the destination parameter exists in the url path, the page will jump directly to the url indicated by destination, which cannot be controlled.
3. how to implement multiple steps forms multiple steps, or how to obtain submitted values 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.
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
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, the current page is displayed by default. Drupal_goto (current_path (), array ('query' => drupal_get_query_parameters (); this is done in the API.
2. when the Form destination (destination) is specified, the jump address can also be changed.
In the drupal_goto function, you can see that if the destination parameter exists in the url path, the page will directly go to the link pointed to by destination. as a result, after multiple buttons under some forms are submitted, the pages that should have been redirected by redirect are also different.
Therefore, in the form # submit function, destination can be directly deleted in some operations.
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']);
}
The method I used is to redefine a url and pass destination, but delete destination from $ _ GET. However, the destination jump of destination is usually used.
3. Form implements multiple steps. Form is reloaded to obtain the value submitted by Form.
In fact, these problems are all in the final sense, that is, let the form continue to be submitted. Instead of refreshing the page. You only need to execute the following code in the # submit function of form:
The code is as follows: if ($ form_state ['values'] ['OP'] = t ("Next Step ")){
$ Form_state ['rebuilt'] = TRUE;
$ Form_state ['store'] ['users'] = $ form_state ['values'] ['users'];
}
In the define definition of form, you can get the value $ form_state ['store'] ['users.
Refer to Drupal7 related API functions:
Drupal_redirect_form
Drupal_goto
Drupal_get_destination