我有一种表单,当提交和验证时,需要重定向到页面以创建节点(节点/添加/ factura-tmn),但我想向此页面发送参数。是否有可能?
我目前有以下代码:
function add_invoice_file_form_submit($form, &$form_state) { $form_state['redirect'] = 'node/add/factura-tmn'; drupal_redirect_form($form_state); }
我有一种表单,当提交和验证时,需要重定向到页面以创建节点(节点/添加/ factura-tmn),但我想向此页面发送参数。是否有可能?
我目前有以下代码:
function add_invoice_file_form_submit($form, &$form_state) { $form_state['redirect'] = 'node/add/factura-tmn'; drupal_redirect_form($form_state); }
I have a form that when submitted and validated, needs to be redirected to a page to create a node (node/add/factura-tmn), but I want to send a parameter to this page. Is it possible?
I currently have the following code:
function add_invoice_file_form_submit($form, &$form_state) { $form_state['redirect'] = 'node/add/factura-tmn'; drupal_redirect_form($form_state); }
为什么不仅使用修改后的节点添加表单?您可以将其更改为您想要的任何字段和验证。
Why not just use a modified node add form? You can change it to have whatever fields and validation you want.
function add_invoice_file_form_submit($form, &$form_state) { // files validations... ... $form_state['redirect'] = 'node/add/factura-tmn/' . $fid; drupal_redirect_form($form_state); } function paperless_planning_form_node_form_alter(&$form, $form_state, $form_id) { if(isset($form['type']) && isset($form['#node'])) { $type = $form['#node']->type; switch($type) : case 'factura_tmn': $fid = arg(3); $file = file_load($fid); ... endswitch; } }
the solucion is very simple:
function add_invoice_file_form_submit($form, &$form_state) { // files validations... ... $form_state['redirect'] = 'node/add/factura-tmn/' . $fid; drupal_redirect_form($form_state); } function paperless_planning_form_node_form_alter(&$form, $form_state, $form_id) { if(isset($form['type']) && isset($form['#node'])) { $type = $form['#node']->type; switch($type) : case 'factura_tmn': $fid = arg(3); $file = file_load($fid); ... endswitch; } }
如果要处理表单,则可以使用 drupal_form_submit()。文档页面中报告的示例显示了如何使用该函数。
// Register a new user. $form_state = array(); $form_state['values']['name'] = 'robo-user'; $form_state['values']['mail'] = 'robouser@example.com'; $form_state['values']['pass']['pass1'] = 'password'; $form_state['values']['pass']['pass2'] = 'password'; $form_state['values']['op'] = t('Create new account'); drupal_form_submit('user_register_form', $form_state);
在表单提交处理程序中,没有必要调用 drupal_redirect_form()
;代码只需要设置 $form_state['redirect']
。请参阅窗口提交处理程序所做的内容,例如
If you want to process a form, you can use drupal_form_submit(). The example reported in the documentation page shows how to use the function.
// Register a new user. $form_state = array(); $form_state['values']['name'] = 'robo-user'; $form_state['values']['mail'] = 'robouser@example.com'; $form_state['values']['pass']['pass1'] = 'password'; $form_state['values']['pass']['pass2'] = 'password'; $form_state['values']['op'] = t('Create new account'); drupal_form_submit('user_register_form', $form_state);
Inside a form submission handler, it's not necessary to call drupal_redirect_form()
; the code just need to set $form_state['redirect']
. See what is done from form submission handlers implemented by Drupal core modules, such as system_modules_submit(), aggregator_form_opml_submit(), and comment_multiple_delete_confirm_submit().
© 2022 it.wenda123.org All Rights Reserved. 问答之家 版权所有