By Tymon on
I have my own node type and I wanna have multipage form. I'm doing it like here: http://drupal.org/node/101707 but it not works. I want to use multipage form in function mynode_form while adding new content, which is called from Create Content -> Mynode. Maybe I forgot to add some function or extra parameters?
Comments
more
I'll give more info.
When I'am adding content, I have first page of form displayed OK, then I push "submit" button, and I get info "Your node has been created" and I dont have second page displayed.
and here are my functions:
I have done it like
I have done it like this.....may it help you. It is two step form.
function newsite_form($form_values = NULL){
global $user;
if(!$user->uid || $user->uid==''){
// $edit = $_POST['edit'];
if (!isset($form_values)) {
$step = 1;
}
if($form_values['op'] == 'Back') {
$step = $form_values['step'] - 1;
}
if($form_values['op'] == 'Next') {
$step = $form_values['step'] + 1;
}
$form['step'] = array(
'#type' => 'hidden',
'#value' => t($step),
);
$row = Array();
if($user->uid)
$row['uid'] = $user->uid;
else
$row['uid'] = '0';
$row['name'] = '';
$row['type'] = 'group';
$row['comment'] = '0';
$row['status'] = '1';
$row['promot'] = '';
$row['sticky'] = '';
$row['revision'] = '';
$group_type = 'group';
$sql = "SELECT * from node_type where type='group'";
$result = db_query($sql, $types);
$row = db_fetch_object($result);
drupal_set_title(t('Create $row->name', array('$row->name' => $row->name)));
$form['#id'] = 'step';
switch($step) {
case 1: // ----------------------------------------------------------------
//start of hidden field for case 2
$form['profile_fullname'] = array(
'#type' => 'hidden',
'#value' => $form_values['profile_fullname'],
);
$form['user_registration_help'] = array(
'#type' => 'hidden',
'#value' => $form_values['user_registration_help'],
);
$form['affiliates'] = array(
'#type' => 'hidden',
'#value' => $form_values['affiliates'],
);
$form['notify'] = array(
'#type' => 'hidden',
'#value' => $form_values['account']['notify'],
);
$form['destination'] = array(
'#type' => 'hidden',
'#value' => $form_values['destination'],
);
$form['name'] = array(
'#type' => 'hidden',
'#value' => $form_values['name'],
);
$form['mail'] = array(
'#type' => 'hidden',
'#value' => $form_values['mail'],
);
$form['pass[pass1]'] = array(
'#type' => 'hidden',
'#value' => $form_values['pass[pass1]'],
);
$form['pass[pass2]'] = array(
'#type' => 'hidden',
'#value' => $form_values['pass[pass2]'],
);
$form['status'] = array(
'#type' => 'hidden',
'#value' => $form_values['status'],
);
$form['roles'] = array(
'#type' => 'hidden',
'#value' => $form_values['roles'],
);
$form['legal_accept'] = array(
'#type' => 'hidden',
'#value' => $form_values['legal_accept'],
);
//end of hidden fields for case 2
$form['step1'] = array('#type' => 'fieldset',
'#title' => t('Site information'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['step1']['og_public'] = array('#type' => 'value', '#value' => TRUE);
$form['nsite_help'] = array(
'#type' => 'item',
'#value' => t($row->help),
'#weight' => -5,
'#prefix' => '
'#suffix' => '
',
);
$form['step1'] = array_merge_recursive($form['step1'], node_invoke($group_type, 'form', $form_values));
// this upper line creates the title and body fields for this module.
// all group home pages are publically accessible as far as og is concerned. their posts may or may not be.
// change this via hook_form_alter() if you want subscriber only group home pages. this may become part of og.module one day
$form['step1']['og_public'] = array('#type' => 'value', '#value' => TRUE);
$form['step1']['og_description'] = array('#type' => 'textfield', '#title' => t('Description'), '#default_value' => $node->og_description, '#size' => 70, '#maxlength' => 150, '#required' => true, '#description' => t('A brief description for the group details block and the group directory.'), '#weight' => -4);
// $form['step1']['og_website'] = array('#type' => 'textfield', '#title' => t('Group website'), '#default_value' => $node->og_website, '#description' => t('If your group has its own website, enter the address here.'));
if ($node->nid) {
$default = $node->og_selective;
}
else {
// $default = nsite_OPEN;
$default = nsite_MODERATED;
}
// $form['step1']['og_selective'] = array('#type' => 'radios', '#title' => t('Subscription requests'), '#default_value' => $default, '#options' => array(t('open - subscription requests are accepted immediately.'), t('moderated - subscription requests must be approved.'), t('invite only - subscriptions must be created by an administrator.'), t('closed - subscriptions are fully administered by an administrator.')), '#description' => t('How should subscription requests be handled in this group? When you select closed, users will not be able to subscribe or unsubscribe.'));
$form['og_selective'] = array('#type' => 'hidden', '#default_value' => $default, '#options' => array(t('open - subscription requests are accepted immediately.'), t('moderated - subscription requests must be approved.'), t('invite only - subscriptions must be created by an administrator.'), t('closed - subscriptions are fully administered by an administrator.')), '#description' => t('How should subscription requests be handled in this group? When you select closed, users will not be able to subscribe or unsubscribe.'));
// directory checkbox
$visibility = variable_get('nsite_visibility_directory', nsite_DIRECTORY_CHOOSE_FALSE);
// override for admins - get right default
if (user_access('administer nodes')) {
$visibility = in_array($visibility, array(nsite_DIRECTORY_NEVER, nsite_DIRECTORY_CHOOSE_FALSE)) ? nsite_DIRECTORY_CHOOSE_FALSE : nsite_DIRECTORY_CHOOSE_TRUE;
}
$default = FALSE;
switch ($visibility) {
case nsite_DIRECTORY_NEVER:
$form['step1']['og_directory'] = array('#type' => 'value', '#value' => 0);
break;
case nsite_DIRECTORY_ALWAYS:
$form['step1']['og_directory'] = array('#type' => 'value', '#value' => 1);
break;
case nsite_DIRECTORY_CHOOSE_TRUE:
$default = TRUE;
// fall through
case nsite_DIRECTORY_CHOOSE_FALSE:
$form['step1']['og_directory'] = array('#type' => 'checkbox', '#title' => t('list in groups directory'), '#default_value' => $node->nid ? $node->og_directory : $default, '#description' => t('Should this group appear on the !page?', array('!page' => l(t('list of groups page'),'og'))));
break;
}
// language
if (module_exists('locale') && $languages = locale_supported_languages()) {
if (count($languages['name']) > 1) {
$languages['name'] = array_map('check_plain', $languages['name']);
$form['step1']['locale']['og_language'] = array('#type' => 'radios',
'#title' => t('Language'),
'#default_value' => $node->og_language,
'#options' => $languages['name'],
'#description' => t('Selecting a different locale will change the interface language of the group. Users who have chosen a preferred language always see their chosen language.'),
);
}
}
$subs = og_get_subscriptions($row->uid);
foreach ($subs as $key => $val) {
$groups[$key] = $val['title'];
}
$cnt = count($groups);
// show multi-select. if less than 20 choices, use checkboxes.
if(module_exists('og_author')){
$form['step1']['og_author'] = array('#type' => 'select',
'#title' => t('Author group'),
'#options' => $groups,
'#required' => $required,
'#description' => t('Select the group that will be authoring this post.'),
'#required' => $required,
'#multiple' => FALSE);
} // end of if for module_exist(og_author)
$form['step1']['back'] = array(
'#type' => 'hidden',
'#value' => 'Back',
);
$form['step1']['next'] = array(
'#type' => 'submit',
'#value' => 'Next',
);
break;
case 2: // ----------------------------------------------------------------
//start of hidden fields for case 1
$form['title'] = array(
'#type' => 'hidden',
'#value' => $form_values['title'],
);
$form['og_description'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_description'],
);
$form['body'] = array(
'#type' => 'hidden',
'#value' => $form_values['body'],
);
$form['og_website'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_website'],
);
$form['og_selective'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_selective'],
);
$form['og_directory'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_directory'],
);
$form['og_author'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_author'],
);
$form['og_public'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_public'],
);
//end of fields fields for case 1
$form['step2'] = array('#type' => 'fieldset',
'#title' => t('User Information'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => '0',
);
//$admin = newsite_user_access('administer users');
$admin = user_access('administer users');
// If we aren't admin but already logged on, go to the user page instead.
if (!$admin && $user->uid) {
drupal_goto('user/'. $user->uid);
}
if (!$admin) {
$form['step2']['user_registration_help'] = array('#value' => filter_xss_admin(variable_get('user_registration_help', '')));
}
$affiliates = user_auth_help_links();
if (!$admin && count($affiliates) > 0) {
$affiliates = implode(', ', $affiliates);
$form['step2']['affiliates'] = array('#value' => '
'. t('Note: if you have an account with one of our affiliates (!s), you may login now instead of registering.', array('!s' => $affiliates, '@login_uri' => url('user'))) .'
');
}
$form['step2'] = array_merge($form['step2'], user_edit_form(NULL, NULL, TRUE));
if ($admin) {
$form['step2']['account']['notify'] = array(
'#type' => 'checkbox',
'#title' => t('Notify user of new account')
);
// Redirect back to page which initiated the create request; usually admin/user/user/create
$form['step2']['destination'] = array('#type' => 'hidden', '#value' => $_GET['q']);
}
$null = NULL;
$extra = _user_forms($null, NULL, NULL, 'register');
if (!$extra) {
$form['step2']['name'] = $form['account']['name'];
$form['step2']['mail'] = $form['account']['mail'];
$form['step2']['pass'] = $form['account']['pass'];
$form['step2']['status'] = $form['account']['status'];
$form['step2']['roles'] = $form['account']['roles'];
$form['step2']['notify'] = $form['account']['notify'];
unset($form['account']);
}
else {
$form['step2'] = array_merge($form['step2'], $extra);
}
$form['step2']['back'] = array(
'#type' => 'button',
'#value' => 'Back',
'#weight' => 40,
);
$form['step2']['finish'] = array(
'#type' => 'submit',
'#value' => 'Finish',
'#weight' => 45,
);
break;
}//end of switch
$form['#multistep'] = TRUE;
$form['#redirect'] = FALSE;
$form['#base'] = 'newsite_form';
/* $form['og_theme'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the group.'), $edit['theme'] ? $edit['theme'] : $node->nsite_theme, 2);;*/
return $form;
}// end of if for !user
else{
drupal_goto('node/add/group');
}
} // end of function newsite_form
CRINCH