【问题标题】:drupal 7 chain formsdrupal 7 链表
【发布时间】:2012-01-06 10:34:39
【问题描述】:

我有一个表格 A 和一个表格 B。

我想让表单 A 将用户重定向到表单 B 并通知表单 B 在表单 A 中所做的选择

Form A的提交功能(不起作用):

function recruitment_select_team_submit($form, &$form_state)
{
    // Forward to the next page.
    $items['yourmod/foo/%/delete'] = array(
    'title' => 'goto next page',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('recruitment_form', 1), // second argument is the paramter for the team_id (test value)
    //'access arguments' => array('delete foo rows'),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    );

    return $items;
}

表格B的表格:

function recruitment_form()
{
    $team_id = 1;
    if(db_query('select count(*) from gm_team where id = :team_id',array(':team_id' => $team_id))->fetchfield() == 0)
    {
        die('Sorry but the team with team ID '.$team_id.' does not exist. If you feel this is a mistake please contact us.');
    }
    $team_terms = db_query('select terms from gm_team where id = :team_id',array(':team_id' => $team_id))->fetchfield();
    $team_requirements = db_query('select recruit_requirements from gm_team where id = :team_id',array(':team_id' => $team_id))->fetchfield();  

......
}

【问题讨论】:

  • 您可以使用 1) Db 将数据存储到两个表单都可以访问它的位置。 2)至于重定向,您可以使用 jquery 来做到这一点
  • This 可能会帮助你
  • hakanito 的链接是处理此问题的正确方法,除非您真的有充分的理由不将其设为多格式。
  • 确实 hakanito 的链接是一个很好的解决方案。

标签: drupal drupal-7


【解决方案1】:

Hanito's link to multiform example in the cmets to your question将是我的第一个建议......但是,如果您确实需要将表单B作为单独的表单或者超出您的控制范围,您可能只存储表单的表单值A 在 session var 中,然后将 $form['redirect'] 值设置为 form b 的路径。

例子。

function recruitment_select_team_submit($form, &$form_state)
{
    // Forward to the next page.
    $items['yourmod/foo/%/delete'] = array(
    'title' => 'goto next page',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('recruitment_form', 1), // second argument is the paramter for the team_id (test value)
    //'access arguments' => array('delete foo rows'),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    );

    $_SESSION['form_a_values'] = $form_state['values'];
    $form['redirect'] = 'path/to/form/B';
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多