Hi Guys,
I have created a set of forms against the URL 'http://localhost/31mayclientdrupal5_newsite/?q=newsite/menu/768', the 768 is the group ID like the OG module has.
I want to create
1) create a blog
2) create a story
3) create an album
.......
......
against this group 768.
I have different collapsible links, which has its own form with submit button. So there is multiple forms.
The forms are being shown well but I am not getting understand how I should submit this form and How I will get know which form is going to be submitted. The code is available for observation.
function test_page($gid = NULL) {
$forms_arr = array('blog','album','story','article');
for($i=0; $i<count($forms_arr); $i++){
$output .= drupal_get_form('test_form', $forms_arr[$i], $gid);
}
return $output;
} // end of function test_page
function test_form($cat_arr, $gids) {
global $user;
$gids = $gid;
$gids = array($gids);
$group_type = $cat_arr;
switch($cat_arr){
case "blog":
$row_blog_form = Array();
if($user->uid)
$row_blog_form['uid'] = $user->uid;
else
$row_blog_form['uid'] = '0';
$sql = "SELECT * from node_type where type='blog'";
$result = db_query($sql);
$row_blog_form = db_fetch_object($result);
$form['#id'] = 'test_form_'.$cat_arr;
$form['#base'] = 'test_form';
$form['newsite_blog'] = array('#type' => 'fieldset',
'#title' => t('Post a blog entry now?'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '<div class="node-form">',
'#suffix' => '</div>',
);
$form['newsite_blog']['gid'] = array('#type' => 'hidden',
'#title' => t(''),
'#value' => $gids,
);
$form['newsite_blog'] = array_merge_recursive($form['newsite_blog'], node_invoke($row_blog_form->type, 'form', $gids));
$c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $group_type);
while ($vocabulary = db_fetch_object($c)) {
if ($vocabulary->tags) {
$typed_terms = array();
foreach ($terms as $term) {
// Extract terms belonging to the vocabulary in question.
if ($term->vid == $vocabulary->vid) {
// Commas and quotes in terms are special cases, so encode 'em.
if (strpos($term->name, ',') !== FALSE || strpos($term->name, '"') !== FALSE) {
$term->name = '"'.str_replace('"', '""', $term->name).'"';
}
$typed_terms[] = $term->name;
}
}
$typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);
if ($vocabulary->help) {
$help = $vocabulary->help;
}
else {
$help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".');
}
$form['newsite_blog']['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield',
'#title' => $vocabulary->name,
'#description' => $help,
'#required' => $vocabulary->required,
'#default_value' => $typed_string,
'#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
'#weight' => $vocabulary->weight,
'#maxlength' => 255,
);
}
else {
// Extract terms belonging to the vocabulary in question.
$default_terms = array();
foreach ($terms as $term) {
if ($term->vid == $vocabulary->vid) {
$default_terms[$term->tid] = $term;
}
}
$form['newsite_blog']['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help);
$form['newsite_blog']['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
$form['newsite_blog']['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required;
}
}
if (is_array($form['newsite_blog']['taxonomy']) && !empty($form['newsite_blog']['taxonomy'])) {
if (count($form['newsite_blog']['taxonomy']) > 1) { // Add fieldset only if form has more than 1 element.
$form['newsite_blog']['taxonomy'] += array(
'#type' => 'fieldset',
'#title' => t('Categories'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
}
$form['newsite_blog']['taxonomy']['#weight'] = -3;
$form['newsite_blog']['taxonomy']['#tree'] = TRUE;
}
///////////////////////////////////////////////getting from og/////////////////////////////////
$required = variable_get('og_audience_required', 0) && !user_access('administer nodes');
if (user_access('administer nodes')) {
$options = og_all_groups_options();
}
else {
$subs = og_get_subscriptions($user->uid); //changed
foreach ($subs as $key => $val) {
$options[$key] = $val['title'];
}
}
$vis = variable_get('og_visibility', 0);
if (user_access('administer organic groups') && $vis < 2) {
$vis = $vis == OG_VISIBLE_GROUPONLY ? OG_VISIBLE_CHOOSE_PRIVATE : OG_VISIBLE_CHOOSE_PUBLIC;
}
elseif (!count($options)) {
// don't show checkbox if no subscriptions. must be public.
$vis = OG_VISIBLE_BOTH;
}
switch ($vis) {
case OG_VISIBLE_BOTH:
$form['newsite_blog']['og_public'] = array('#type' => 'value', '#value' => 1);
break;
case OG_VISIBLE_GROUPONLY:
$form['newsite_blog']['og_public'] = array('#type' => 'value', '#value' => 0);
break;
//user decides how public the post is.
case OG_VISIBLE_CHOOSE_PUBLIC:
$form['newsite_blog']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 1, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always <em>Public</em>.'), '#weight' => 2);
break;
case OG_VISIBLE_CHOOSE_PRIVATE:
$form['newsite_blog']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 0, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always <em>Public</em>.'), '#weight' => 2);
break;
}
$simple = !user_access('administer organic groups') && !variable_get('og_audience_checkboxes', TRUE) && count($gids);
if (count($options) == 1 && $required) {
$gids = array_keys($options);
$gid = $gids[0];
$groups = array($gid);
// also show read only mode if user has 1 option and we are in required mode
$simple = TRUE;
}
elseif ($gids) {
// populate field from the querystring if sent
$groups = $gids;
if (!user_access('administer nodes')) {
// filter out any groups where author is not a member. we cannot rely on fapi to do this when in simple mode.
$groups = array_intersect($gids, array_keys($options));
}
}
elseif ($node->nid || $node->og_groups) {
$groups = $node->og_groups;
}
else {
$groups = array();
}
if ($simple) {
// 'simple' mode. read only.
if (count($groups)) {
foreach ($groups as $gid) {
$titles[] = $options[$gid];
$item_value = implode(', ', $titles);
}
$form['newsite_blog']['visible']['og_groups_visible'] = array('#type' => 'item', '#title' => t('Audience'), '#value' => $item_value);
$assoc_groups = drupal_map_assoc($groups);
// this hidden element persists audience values during a Preview cycle. avoids errors on Preview.
$form['newsite_blog']['invisible']['og_groups_hidden'] = array('#type' => 'hidden', '#value' => serialize($assoc_groups));
// this 'value' element persists the audience value during submit process
$form['newsite_blog']['invisible']['og_groups'] = array('#type' => 'value', '#value' => $assoc_groups);
}
}
elseif ($cnt = count($options)) {
drupal_add_js(drupal_get_path('module', 'og'). '/og.js');
// show multi-select. if less than 20 choices, use checkboxes.
$type = $cnt >= 20 ? 'select' : 'checkboxes';
$form['newsite_blog']['visible']['og_groups'] = array(
'#type' => $type,
'#title' => t('Audience'),
'#attributes' => array('class' => 'og-audience'),
'#options' => $options,
'#required' => $required,
'#description' => format_plural(count($options), 'Show this post in this group.', 'Show this post in these groups.'),
'#default_value' => $gids,
'#required' => $required,
'#multiple' => TRUE);
}
else if ($required) {
form_set_error('title', t('You must !join before posting a %type.', array('!join' => l(t('join a group'), 'og'), '%type' => node_get_types('name', $node->type))));
}
if (count($form['newsite_blog']['visible']) > 1) {
$form['newsite_blog']['#type'] = 'fieldset';
$form['newsite_blog']['#title'] = t('Groups');
$form['newsite_blog']['#collapsible'] = TRUE;
$form['newsite_blog']['#collapsed'] = $gids ? TRUE : FALSE;
}
$form['newsite_blog']['author']['og_author'] = array('#type' => 'select',
'#title' => t('Author group'),
'#options' => $options,
'#required' => $required,
'#description' => t('Select the group that will be authoring this post.'),
'#required' => $required,
'#multiple' => FALSE);
$form['newsite_blog']['author']['#type'] = 'fieldset';
$form['newsite_blog']['author']['#title'] = t('Author group');
$form['newsite_blog']['author']['#collapsible'] = TRUE;
$form['newsite_blog']['author']['#weight'] = 1;
//////////////////////////////////////////////end /////////////////////////////////////////////
//////////////////////////////////////start upload module////////////////////////////////////////////////////////////////////
drupal_add_js('misc/progress.js');
drupal_add_js('misc/upload.js');
$form['newsite_blog']['attachments'] = array(
'#type' => 'fieldset',
'#access' => user_access('upload files'),
'#title' => t('File attachments'),
'#collapsible' => TRUE,
'#collapsed' => empty($node->files),
'#description' => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
'#prefix' => '<div class="attachments">',
'#suffix' => '</div>',
'#weight' => 30,
);
// Wrapper for fieldset contents (used by upload JS).
$form['newsite_blog']['attachments']['wrapper'] = array(
'#prefix' => '<div id="attach-wrapper">',
'#suffix' => '</div>',
);
// Make sure necessary directories for upload.module exist and are
// writable before displaying the attachment form.
$path = file_directory_path();
$temp = file_directory_temp();
// Note: pass by reference
if (!file_check_directory($path, FILE_CREATE_DIRECTORY) || !file_check_directory($temp, FILE_CREATE_DIRECTORY)) {
$form['newsite_blog']['attachments']['#description'] = t('File attachments are disabled. The file directories have not been properly configured.');
if (user_access('administer site configuration')) {
drupal_set_message(t('I am in fifth if condition'));
$form['newsite_blog']['attachments']['#description'] .= ' '. t('Please visit the <a href="@admin-file-system">file system configuration page</a>.', array('@admin-file-system' => url('admin/settings/file-system')));
}
else {
$form['newsite_blog']['attachments']['#description'] .= ' '. t('Please contact the site administrator.');
}
}
else {
$form['newsite_blog']['attachments']['wrapper'] += _upload_form($node);
$form['newsite_blog']['#attributes']['enctype'] = 'multipart/form-data';
}
//////////////////////////////////////////////end /////////////////////////////////////////////
$form['newsite_blog']['Submit'] = array(
'#type' => 'submit',
'#value' => 'Submit Blog',
'#weight' => 45,
);
return $form;
break;
case "album":
$form['#id'] = 'test_form_'.$cat_arr;
$form['#base'] = 'test_form';
$form['newsite_album'] = array(
'#type' => 'fieldset',
'#title' => t('Would you start your photo album now?'),
'#weight' => 3,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '<div class="node-form">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
$form['newsite_album']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $edit['description'],
'#cols' => 60,
'#rows' => 5,
);
$form['newsite_album']['Submit']= array(
'#type' => 'submit',
'#value' => 'Submit Album',
'#weight' => 45,
);
return $form;
break;
case "story":
echo "You want to create story form".$cat_arr;
break;
case "article";
echo "you want to create article form".$cat_arr;
break;
} //end of switch
} // end of fuction test_form
function test_form_submit($form_id, $form_values){
print "you want to submit this form................".$form_id;
}
I have tried this code but it is not showing form_id I mean which form is going to be submitted.
If anyone has such sort of idea, I am waiting for your help.
Thanks in advance.
CRINCH.