I am developing a module for supporting multipage user registration forms based on role. It is an entire application process that is going to take people several hours to complete and in the end will support saving progress via session and cookies, and maybe even a temp account or code. Right now I am beginning and got a multipage form with all the required fields set up etc. I however am having a problem.
The application/registration gets to page 2 and when I hit next it doesn't ever run my multipage_registration_form_alter function instead stopping progress when it doesn't see name and email in form_state. I can put it in manually in multipage_form_user however it then creates the user and altho it shows the next page... it is then editing instead of applying.
My question is why is it not getting to my code after page two, to even respect form_state['rebuild'] being set to true and why is it running the code 2x on page 2. Debug output and module code below.
Initial Load:
Page 1 of 8
Array ( [storage] => Array ( [page] => 1 [values] => Array ( [0] => ) ) [submitted] => [post] => Array ( ) [rebuild] => 1 [#validate] => Array ( [0] => multipage_registration_user_register_validate ) )
First click of "Next >":
Page 1 of 8<br>Array
(
[storage] => Array
(
[page] => 1
[values] => Array
(
[0] =>
)
)
[submitted] =>
[post] => Array
(
[name] => test
[mail] => test@test.com
[profile_last_name] => Testlast
[profile_first_name] => Testfirst
[profile_gender] => Male
[profile_middle_initial] => T
[timezone] => -21600
[form_build_id] => form-fe40e26af8a7e7821b404c55b026737e
[form_id] => user_register
[op] => Next >
)
[rebuild] => 1
[#validate] => Array
(
[0] => multipage_registration_user_register_validate
)
)
Page 2 of 8<br>Array
(
[storage] => Array
(
[page] => 2
[values] => Array
(
[0] =>
[1] => Array
(
[name] => test
[mail] => test@test.com
[profile_last_name] => Testlast
[profile_first_name] => Testfirst
[profile_gender] => Male
[profile_middle_initial] => T
[timezone] => -21600
[op] => Next >
[submit] => Next >
[form_build_id] => form-b79377fd1faef029c0e2dcedbf82ad7b
[form_id] => user_register
)
)
)
[submitted] => 1
[rebuild] => 1
[#validate] => Array
(
[0] => multipage_registration_user_register_validate
)
[values] => Array
(
[name] => test
[mail] => test@test.com
[profile_last_name] => Testlast
[profile_first_name] => Testfirst
[profile_gender] => Male
[profile_middle_initial] => T
[timezone] => -21600
[op] => Next >
[submit] => Next >
[form_build_id] => form-b79377fd1faef029c0e2dcedbf82ad7b
[form_id] => user_register
)
[clicked_button] => Array
(
[#type] => submit
[#value] => Next >
[#weight] => 30
[#id] => next
[#post] => Array
(
[name] => test
[mail] => test@test.com
[profile_last_name] => Testlast
[profile_first_name] => Testfirst
[profile_gender] => Male
[profile_middle_initial] => T
[timezone] => -21600
[form_build_id] => form-fe40e26af8a7e7821b404c55b026737e
[form_id] => user_register
[op] => Next >
)
[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => submit
)
[#array_parents] => Array
(
[0] => submit
)
[#processed] =>
[#description] =>
[#attributes] => Array
(
)
[#required] =>
[#input] => 1
[#name] => op
[#button_type] => submit
[#executes_submit_callback] => 1
[#process] => Array
(
[0] => form_expand_ahah
)
)
)
Third click of "Next >":
No output as it never gets to the debugging statements in multipage_registration_form_alter
However it does say:
* You must enter a username.
* You must enter an e-mail address.
Code below:
<?php
// $Id$
function multipage_registration_form_alter($form, $form_state, $form_id){
switch($form_id){
case 'user_register':
$showcats = array(
2,
2,
2,
1,
1,
1,
1,
3
);
$page = null;
if($form_state['submitted'] == 1 && $form_state['clicked_button']['#id'] == 'next'){
$form_state['storage']['page']++;
}
$lastpage = count($showcats);
if(isset($form_state['storage']['page'])) {
$page = $form_state['storage']['page'];
if(!isset($form['values']['name'])) $form['values']['name'] = $form_state['storage']['values']['name'];
if(!isset($form['values']['mail'])) $form['values']['mail'] = $form_state['storage']['values']['mail'];
} else {
$page = $form_state['storage']['page'] = 1;
}
echo "Page $page of $lastpage<br>";
$form_state['storage']['values'][$page - 1] = $form_state['values'];
#print_r("values: ".$form_state['values']);
if($form_state['clicked_button']['#id'] == 'prev'){
$page = $page - 1;
echo "prev set<br>";
unset($form_state['values']['prev']);
}
$countstart = 0;
$countend = 0;
for($i=0;$i<$page;$i++){
$countstart += $showcats[$i];
$countend += $showcats[$i];
}
$countstart -= $showcats[$i - 1];
$categories = _profile_category_weight_categories();
$count = 0;
foreach($categories as $formkey=>$weight){
if($count >= $countend || $count < $countstart){
unset($form[$formkey]);
}
$count++;
}
$form['submit']['#value'] = t('Next >');
$form['submit']['#id'] = 'next';
if($page > 1){
$form['prev'] = array (
'#type'=>'submit',
'#value'=>'< Prev',
'#id'=>'prev'
);
}
if($page == $lastpage){
$form['submit']['#value'] = t('Complete');
}
else $form_state['rebuild'] = TRUE;
$form_state['rebuild'] = TRUE;
$form_state['#validate'] = array('multipage_registration_user_register_validate'); #never gets to this stage
print_r($form_state);
break;
}
}
function multipage_registration_user($type, &$edit, &$user, $category = NULL){
/*
echo "Type: ";
print_r($type);
echo "<br>Edit: ";
print_r($edit);
echo "<br>User: ";
print_r($user);
echo "<br>Category: ";
print_r($category);*/
}
function multipage_registration_user_register_submit($form, &$form_state){
print_r("submit: ".$form);
if(isset($form_state)){
}
}
function multipage_registration_user_register_validate($form,&$form_state){
echo "validate: <br>";
print_r($form_state);
if(isset($form_state)){
}
}
function multipage_registration_help($path,$arg){
$output = '';
switch($path){
default:
$output = '<p>' . t("Help for multipage registraton") . '</p>';
}
}
function multipage_registration_perm(){
return array('access multipage_registration','administer multipage_regristration');
}
Comments
_
Have you considered doing this with existing modules? This can be done pretty simply with content_profile, autoassignrole and optionally rules, content_complete, and pageroute.
I have but they seemed to
I have but they seemed to fall short of what I wanted to do. I think I am going to just compromise however and let the user register before their profile is filled out fully so i can use these modules. I would still like to know why I am following examples and it is working but on the first 2 times..
I didn't consider some of the modules you listed so thank you :)
Could you elaborate a bit
Could you elaborate a bit more on how to accomplish this with those modules? I want to have at least two different roles on my website: users and venues (owners). Upon registration you should choose your profile first and then different registration forms will be shown based on user choice.
Thanks,
Patan
_
The autoassignrole module lets you create links for registering users to different roles. The content_profile module allows you to create different cck based registration forms for each of the roles. The content_complete module tracks how much of the registration forms are completed and rules allows you to automate all sorts of different things based on those roles.
The best way to see how it works is to setup a test site and try it out.
Thanks for your reply, I will
Thanks for your reply, I will set them all up and give it a try.
Patan
How to set up this page route url for user registration form.
Hi, WorldFallz
First of all I would like to appreciate for this forum discussion, I have been seaching for this concept for more than 5 days.
I have managed to generate a multi step form which will be used as the user registration form for the website for which I am working on. But how can I setup the url of this form as the link to "Create new account".
Any help is greatly appreciated.
Thanks, Pradeep.
_
Where? In the default login block?
Sorry, for the insufficient information.
Sorry, for the insufficient information. Yes you are right in the default login block, infact I would like to place this pageroute url in the administrator feature as well, where there is a link which will provide an option for createing new account, where the admin also has an choice to create new account from his/her side.
_
No need to create a duplicate thread -- probably the easiest way to do this is to copy the user_login_block function from user.module into your own custom module (you'll need to rename it appropriately) and alter it as desired.
I used pageroute module as
I used pageroute module as suggested but several problems:
after the first page it is not calling my hook_form_alter() if there is a required field missing, or not even at all in some cases.
The back button validates, which it shouldn't, I found a fix but it won't work without calling my hook_form_alter.
This is problematic, I'm stuck with a form I can't validate. found a post but no one shows solutions: http://drupal.org/node/671574
and back button:
http://drupal.org/node/480008