hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/**
* Implements hook_permission().
*/
function [my-module-name]_permission() {
return array(
'authorize fbauth_connect' => array(
'title' => t('Connect Facebook account and store access token'),
),
);
}
/**
* Implements hook_entity_info().
*/
function drills_ch_vocabulary_entity_info()
{
return array(
'my_vocabulary' => array(
'label' => t('My Vocabulary'),
'entity class' => 'MyVocabularyEntity',
'controller class' => 'MyVocabulryController',
'base table' => 'my_vocabulary',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'entity_id',
'label' => 'vocabulary',
),
'bundles' => array(
'my_vocabulary' => array(
'label'=>'My Vocabulary',
'admin' => array(
'path' => 'admin/structure/my-vocabulary/manage',
'access arguments' => array('administer my vocabulary'),
'controller class' => 'EntityDefaultUIController',
),
),
),
'view modes' => array(
'full' => array(
'label' => t('Default'),
'custom settings' => FALSE,
),
),
'module' => 'my_vocabulary',
'access callback' => 'my_vocabulary_access',
),
);
}
// entity/entity.module の659行あたり
function entity_access($op, $entity_type, $entity = NULL, $account = NULL) {
if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) {
return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type);
}
}
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/**
* Implements hook_permission().
*/
function [my-module-name]_permission() {
return array(
'authorize fbauth_connect' => array(
'title' => t('Connect Facebook account and store access token'),
),
);
}
/**
* Access callback for endity
*/
function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) {
global $user;
if (!isset($account)) {
$account = $user;
}
switch ($op) {
case 'create':
return user_access('administer vocabulary', $account)
|| user_access('create vocabulary', $account);
case 'view':
return user_access('administer vocabulary', $account)
|| user_access('view vocabulary', $account);
case 'edit':
case 'save': // save permission created by entity_rule.inc
return user_access('administer vocabulary')
|| user_access('edit any vocabulary')
|| (user_access('edit my own vocabulary') && ($entity->uid == $account->uid));
case 'delete':
return user_access('administer vocabulary')
|| user_access('delete any vocabulary')
|| (user_access('edit my own vocabulary') && ($entity->uid == $account->uid));
}
}
/**
* Implements hook_entity_info().
*/
function drills_ch_vocabulary_entity_info()
{
return array(
'my_vocabulary' => array(
'label' => t('My Vocabulary'),
'entity class' => 'MyVocabularyEntity',
'controller class' => 'MyVocabulryController',
'base table' => 'my_vocabulary',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'entity_id',
'label' => 'vocabulary',
),
'bundles' => array(
'my_vocabulary' => array(
'label'=>'My Vocabulary',
'admin' => array(
'path' => 'admin/structure/my-vocabulary/manage',
'access arguments' => array('administer my vocabulary'),
'controller class' => 'EntityDefaultUIController',
),
),
),
'view modes' => array(
'full' => array(
'label' => t('Default'),
'custom settings' => FALSE,
),
),
'module' => 'my_vocabulary',
'access callback' => 'my_vocabulary_access',
),
);
}
// entity/entity.module の659行あたり
function entity_access($op, $entity_type, $entity = NULL, $account = NULL) {
if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) {
return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type);
}
}
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){
global $user ;
// データがすでに存在するか否かのチェック
$my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll();
// ajaxコールバック時に使用するパラメーター
$form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ;
$form_state['ch_vocabulary'] = $entity ;
// ajaxのチェックボックスフォーム定義
$form['ch_voca_form']=array(
'#type' => 'checkbox',
'#disabled' => $user->uid == 0 ? true : false ,
'#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'),
'#default_value' => count($my_voca_result)>0 ? 1 : 0,
'#ajax' => array(
'callback' => 'add_to_my_vocabulary_callback',
'wrapper' => 'ch-voca-check-op-'.$entity->vid,
'method' => 'replace',
'effect' => 'fade',
),
);
return $form ;
}
// ajaxのコールバック関数
function add_to_my_vocabulary_in_views($form, $form_state){
global $user;
$entity = $form_state['ch_vocabulary'] ;
// DBにデータがある場合に削除処理
if( $form_state['has_my_voca_result'] ) {
db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute();
// チェックボックスのラベルを「Add」に変更
return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>');
}
// データがなければ、ch_vocabuaryをmy_vocabuaryにコピー
$my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid));
$my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca );
$my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ;
.... //各種フィールド、プロパティのセット
$my_voca_wrapper->save(); // コピーされたデータの保存
// チェックボックスのラベルを「Remove」に変更
return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>');
}
YOUR_MODULE_NAME_menu(){
$items['your/path/%entity'] = array(
'title' => 'Copy and Remove',
'page callback' => 'ajax_add_to_my_vocabulary',
'page arguments' => array(array(), array(), 2) ,
'access arguments' => array('create my vocabulary'),
);
}
YOUR_MODULE_NAME_menu(){
$items['your/path/%entity'] = array(
'title' => 'Copy and Remove',
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_add_to_my_vocabulary', 2) ,
'access arguments' => array('create my vocabulary'),
);
}
function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview'),
'weight' => -10,
'file' => 'node.admin.inc',
);
// …
return $items;
}

フォーム(form)をカスタマイズ時に、hook_form_alter、hook_form_FORM_ID_alter、hook_form_BASE_FORM_ID_alterの何れかを実装して行います。ここで、既存のフォームを特定するために、そのform_idが必要となってきまして、どこでカスタマイズ先のフォームIDを取得するのかは戸惑いました。
例えば、LDAPモジュールをインストールして、認証関連設定ページ(Home » Administration » Configuration » People » LDAP Configuration のAUTHENTICATIONタブ)で、その設定フォームのform_idを見てみましょう。
/**
* Implement hook_form
*/
function your_custom_form($node, &$form_state) {
$form['type'] = array(
'#type' => 'radios',
'#options' => array(
'agree' => t('賛成'),
'disagree' => t('反対'),
),
'#title' => t('投票してください'),
);
$form['survey'] = array(
'#type' => 'fieldtext',
'#title' => t('反対意見'),
'#states' => array(
'visible' => array(
':input[name="type"]' => array('value' => 'disagree'),
),
),
);
}
/**
* Implementation of hook_menu()
* 新規フォームを表示するページのメニュー設定
*/
function my_module_name_menu() {
$items['test/form'] = array(
'title' => 'Ajaxテスト',
'page callback' => 'drupal_get_form',
'page arguments' => array('my_sample_form'),
'access arguments' => array('access content'),
);
}
/**
* フォームの各要素の記述
*/
function my_sample_form($form, &$form_state){
// メッセージ入力フィールド
$form['message'] = array(
'#type' => 'textfield',
'#title' => t('メッセージを入力'),
);
// 入力されたメッセージをajaxで表示する場所
$form['msg_wrapper'] = array(
'#type' => 'markup',
'#markup' => "",
'#prefix' => '<div id="msg-wrapper">',
'#suffix' => '</div>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'test_sample_form_ajax_callback',
'wrapper' => 'msg-wrapper',
'effect' => 'fade',
),
);
return $form;
}
/**
* ajaxに呼び出される関数
*/
function test_sample_form_ajax_callback($form, $form_state) {
// 入力されたメッセージを指定した場所にセット
$form['msg_wrapper']['#markup'] = '入力されたメッセージ:' .
check_plain($form_state['values']['message']) ;
// 置換する部品を返す
return $form['msg_wrapper'] ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('multiple_step_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* マルチステップフォームの定義
*/
function multiple_step_form($form, &$form_state){
switch( $form_state['pager'] ) {
case 'page_1' :
return page_one_form();
break;
case 'page_2' :
return page_two_form();
break;
}
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_1";
// 任一のメッセージ表示
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_one_form_submit';
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
// ステップの定義
$form_state['pager'] = "page_two";
// 任一のメッセージ表示
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
);
// サブミットボタンのイベントハンドラー
$form['#submit'][] = 'page_two_form_submit';
return $form;
}
/**
* ステップ1のボタンイベントハンドラー
*/
function page_one_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_two";
$form_state['rebuild'] = true;
return ;
}
/**
* ステップ2のボタンイベントハンドラー
*/
function page_two_form_submit($form, &$form_state){
$form_state['pager']['card_page']= "page_one";
$form_state['rebuild'] = true;
return ;
}
/**
* メニューでURLの定義
*/
function your_module_menu() {
$items['form/multiple-step'] = array(
'title' => t('Multiple Step Form Test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_one_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* ステップ1 フォームの定義
*/
function page_one_form( $form, &$form_state ){
$form['message_field'] = array(
'#type' => 'markup',
'#markup' => 'Form Step 1',
);
// サブミットボタン
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_1_ajax_callback',
),
);
return $form;}
}
/**
* ステップ2 フォームの定義
*/
function page_two_form( $form, &$form_state ){
$form['test_form']=array(
'#type' => 'item',
'#title' => 'Multiple Step Form',
'#markup' => '<p>Step 2</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => '送信',
'#ajax' => array(
'callback' => 'card_2_ajax_callback',
),
);
return $form;
}
/**
* ステップ1のコールバック関数
*/
function card_1_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_two_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main',
'<section class="block block-system clearfix"
id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* ステップ2のコールバック関数
*/
function card_2_ajax_callback($form, &$form_state){
// 次のステップのフォームの用意
$form = drupal_rebuild_form( 'card_one_form', $form_state );
// フォームのHTML部分の置換コマンド用意
$commands[]=ajax_command_replace( '#block-system-main','<section class="block block-system clearfix" id="block-system-main">'.render($form).'</section>' );
return array('#type' => 'ajax', '#commands' => $commands);
}