[英]Drupal 7 redirect to a specific page (a tab) after form submit
I'm trying to redirect the page after i submited the form. 在我提交表单后,我正在尝试重定向页面。 The form is at the page 'formulaires/demande-de-subvention-pour-les-entraineurs' and i want to redirect to 'formulaires/demande-de-subvention-pour-les-entraineurs/entraineurs' How can i do this?
表格在页面'formulaires / demande-de-subvention-pour-les-entraineurs',我想重定向'公式/ demande-de-subvention-pour-les-entraineurs / entraineurs'我怎么能这样做?
function ulsform_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'ulsform_demande_de_subvention_pour_les_entraineurs_form') {
$form['#submit'][] = 'ulsform_demande_submited_form';
}else if($form_id == 'ulsform_demande_de_subvention_pour_les_entraineurs_02_form'){
$form['#submit'][] = 'ulsform_entraineur_submited_form';
}
}
function ulsform_demande_submited_form(&$form, $form_state){
global $user;
$v = $form_state['values'];
$form_state['redirect'] = 'formulaires/demande-de-subvention-pour-les-entraineurs/entraineurs';
/* My code to insert into the db */
}
It doesn't work and when i try to create a form['#redirect'] like a saw on another post, it doesn't work too. 它不起作用,当我尝试在另一个帖子上创建一个类似锯子的表单['#redirect']时,它也不起作用。 What can i try?
我该怎么办?
Thank you for your help! 谢谢您的帮助! I'm new to drupal
我是drupal的新手
You've forgotten to pass $form_state
by reference, so your changes work only in the form_alter
function. 您忘记通过引用传递
$form_state
,因此您的更改仅适用于form_alter
函数。
Change your function signature as follows. 更改您的功能签名如下。 Note
&$form_state
: 注意
&$form_state
:
function ulsform_form_alter(&$form, &$form_state, $form_id) {
$form_state['redirect'] could be either an array or a simple string. $ form_state ['redirect']可以是数组或简单字符串。 if it's a string, user will be redirected there.
如果它是一个字符串,用户将被重定向到那里。 If it's an array, it will work according to how drupal_goto works.
如果它是一个数组,它将根据drupal_goto的工作方式工作。
$form_state['redirect'] = array(
'node/123',
array(
'query' => array(
'foo' => 'bar',
),'fragment' => 'baz');
To node/123?foo=bar#baz
至
node/123?foo=bar#baz
$form_state['redirect'] = 'node/123'
to node/123
到
node/123
I have the following code in a custom module and after editing the content it is always redirect to /admin/content 我在自定义模块中有以下代码,在编辑内容后,它总是重定向到/ admin / content
function redirect_to_edit_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "page_article_node_form") {
$form['#submit'][] = "_redirect_to_edit";
}
}
function _redirect_to_edit($form, &$form_state) {
$form_state['redirect'] = array(
'node/' . $form['nid']['#value'],
array(
'query' => array(
'destination' => 'node/' . $form['nid']['#value'],
)
)
);
dpm($form_state);
drupal_set_message("L'article a été mis à jour.", 'status');
}
The query part I added as last try. 我上次尝试添加的查询部分。 After the submission I can read my custom message but I can't make the user stays at the edit page.
提交后我可以阅读我的自定义消息,但我不能让用户留在编辑页面。
What am I skipping? 我跳的是什么?
Thanks. 谢谢。
EDIT: 编辑:
Regarding https://www.drupal.org/node/1074616 and my experienced in the issue, there cases that redirection doesn't work. 关于https://www.drupal.org/node/1074616和我在该问题上的经验,有些情况下重定向不起作用。 For me, I have achieved to make the desired redirection like this:
对我来说,我已经实现了如下所需的重定向:
function redirect_to_edit_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "page_article_node_form") {
//$form['actions']['submit']['#submit'][] = '_redirect_to_edit';
$form['#action'] = '?destination=node/' . $form['nid']['#value'] . '/edit';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.