Drupal 7 цепных форм - PullRequest
       4

Drupal 7 цепных форм

1 голос
/ 25 ноября 2011

У меня есть форма A и форма 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,
    );

    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 Ответ

1 голос
/ 27 ноября 2011

Ссылка Hanito на мультиформный пример в комментариях к вашему вопросу была бы моей первой рекомендацией ... однако, если вам действительно нужна форма B, чтобы она была отдельной формой или она была вне вашего контроля, вы, вероятно, могли бы просто хранить значения формыA в сеансе var, а затем установите значение $ form ['redirect'] на путь формы 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';
}
...