Hi guys,

I have a multi page form with a switch depending of the step. How could I specify the name of the other page depending of the step?

There is my code:


//--------------------------------------------
/*HOOK_MENU*/
//--------------------------------------------
function myFirstForm_menu() {
  $items['myFirstForm'] = array(
    'access arguments' => array('access content'),
    'page callback' => 'myFirstForm_abonnement_multistep',
    'title' => 'This is my registration form',
    'type' => MENU_CALLBACK,
  );
   
  return $items;
}
function myFirstForm_abonnement_multistep() {
drupal_get_form('myFirstForm_abonnement_form');
}

//--------------------------------------------
/*MYFIRSTFORM ABONNEMENT FORM*/
//--------------------------------------------
function myFirstForm_abonnement_form(&$form_state, $member = NULL) {
	_user_password_dynamic_validation();
	
	$step = $form_state['storage']['step'];     // STEP1 => ACCEUIL; STEP2 => COORDOONNEES; STEP3 => FINAL STEP, PROFIL
	if (empty($step) || !isset($step)) { $step = 1; }            // we are coming in without a step, so default to step 1
		
	if ($member) $member = (array)$member;
	else $member = array();
	
//	$form = array();
	
	switch ($step) {
/*** STEP1 - PAGE (url) == myfirstform  ***/
		case 1:
			$form['courriel'] = array(
				'#type' => 'textfield',
				'#default_value' => 'Courriel',
				'#maxlength' => 64,
			);
		break;
//------------------------------------------------------

/*** STEP2 - PAGE (url) == myfirstform/abonnement_coordonnees ***/
		case 2:
		    $form['prenom'] = array(
				'#type' => 'textfield',
				'#title' => 'Prénom',
				'#maxlength' => 128,
				'#required' => TRUE,
				'#default_value' => $member['prenom'], 
		    );
		    $form['nom'] = array(
				'#type' => 'textfield',
				'#title' => 'Nom',
				'#maxlength' => 128,
				'#required' => TRUE,
				'#default_value' => $member['nom'], 
		    ); 
			$form['courriel'] = array(
				'#type' => 'textfield', 
				'#title' => 'Courriel', 
				'#default_value' => $_POST['courriel'],
				'#maxlength' => 64,
				'#required' => TRUE,
			  );
					
		   
		    $form['motdepasse'] = array(
				'#type' => 'password_confirm',
				'#required' => empty($member['mid']),
				'#size' => 32,
		    );

		break;
//--------------------------------------------------------

/***STEP3 - PAGE (url) == myfirstform/abonnement_profil ***/
		case 3:
		    $form['sexe'] = array(
				'#type' => 'select',
				'#title' => 'Sexe',
				'#default_value' => $member['sexe'],
				'#options' => array(
				  '' => 'Choisir',
				  '2' => 'Femme',
				  '1' => 'Homme',
				),
				'#prefix' => '<div class="push-down">',
				'#suffix' => '</div>',
			);
  
			$result = db_query("SELECT * FROM {term_data} WHERE vid = 4 AND language = 'fr'");
			  $options_profil = array();
			  while ($profil = db_fetch_object($result)) {
				$options_profil[$profil->tid] = '<strong>' . $profil->name . '</strong><br /><span class="profil">' . $profil->description . '</span>';  
			  }
			  
			$form['profil'] = array(
				'#type' =>  'radios',
				'#title' => 'Quelle description vous ressemble le plus par rapport à vos habitudes de consommation?',
				'#options' => $options_profil,
				'#default_value' => $member['profil'] ? $member['profil'] : 82,
				'#prefix' => '<div class="push-down">',
				'#suffix' => '</div>',
			);
			
		break;
	}
	
	
		//Depending on what page we're on, show the appropriate buttons.
	if ($form_state['storage']['step'] == 1) {
		$form['abonnez'] = array(
			'#type' => 'submit',
			'#value' => 'Abonnez-vous',
			'#attributes' => array('class' => 'submit_accueil'),
		);
	  }
	else if ($form_state['storage']['step'] == 2) {
		$form['next'] = array(
		   '#type' => 'submit',
		   '#value' => 'Enregistrer',
		   '#attributes' => array('class' => 'btnEnregistrer'),
		);
	  }
	else {
		$form['finish'] = array(
		    '#type' => 'submit',
			'#value' => 'Soumettre',
			'#attributes' => array('class' => 'btnEnregistrer'),
		);
	  }
	return $form;
}

//--------------------------------------------
/*MYFIRSTFORM ABONNEMENT FORM SUBMIT*/
//--------------------------------------------

function myFirstForm_abonnement_form_submit($form_id, $form_values) {
	$step = $form_state['storage']['step'];     // STEP1 => ACCEUIL; STEP2 => COORDONNEES; STEP3 => FINAL STEP, PROFIL
	
    $form_state['storage']['values'][$step] = $form_state['values'];   //save the values for the current step into the storage array
    
  if ($form_state['clicked_button']['#id'] != 'edit-finish') {
    $form_state['storage']['step']++;
  }
  else {
    unset($form_state['storage']);
    $form_state['redirect'] = 'myFirstForm/abonnement/confirmation';
  }

    $form_state['rebuild'] = TRUE;
}

}

Thanks for helping me.

Comments

voxy’s picture

Title: How to specify the name's page of the steps of my multi step form? » Multi step form : How to specify the name of the page depending of the step?
linebreak’s picture

Hi Voxy

I think drupal_set_title() is what you're looking for.
By the way instead of writing page callback' => 'myFirstForm_abonnement_multistep' in hook_menu and then creating a function as simple as

<?php function myFirstForm_abonnement_multistep() {
drupal_get_form('myFirstForm_abonnement_form');
} ?>

you can use in hook_menu:

<?php
    'page callback' => 'drupal_get_form',
    'page arguments' => array('myFirstForm_abonnement_form'),
?>

Hope it helps
Antoine

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.