function discussthis_create_form in Discuss This! 6
\brief Create a comment form.
This function is more or less a copy of the Core comment form. It creates a form where the user is expected to enter his/her comment and click Preview/Submit.
\param[in] $form_state The current state of the form \param[in] $nid The node that is being discussed
\return The form in HTML
1 string reference to 'discussthis_create_form'
- _discussthis_menu in ./
discussthis.admin.inc - \brief Actual implementation of hook_menu().
File
- ./
discussthis.module, line 764 - Associations discussions in forums with specific nodes
Code
function discussthis_create_form($form_state, $nid) {
// the user usually enters this function because the topic does not
// exist yet, this form asks for the comment with our own discussthis
// form (i.e. avoid creating a new forum node until the person posts
// his/her comment out)
//
// IMPORTANT: we do NOT check whether the topic already exists because
// it might when the person clicks on Preview. Please, see the submit
// function for more information in that regard. Just don't add a test
// for the topic ID in this function...
// current user has the right to do that?!
if (!user_access('initiate discuss this topics')) {
drupal_access_denied();
return;
}
$title = variable_get('discussthis_new_post_title', '');
if ($title) {
drupal_set_title($title);
}
global $user;
$op = empty($form_state['post']['op']) ? '' : $form_state['post']['op'];
$is_ready = $op == t('Preview') || $op == t('Save');
if ($is_ready) {
$comment = $user;
$comment->comment = check_markup($form_state['post']['comment'], $form_state['post']['format'], FALSE);
$comment->timestamp = time();
$comment->new = FALSE;
// this is not displayed in a very good way, in general
$comment->preview = TRUE;
$comment->subject = $form_state['post']['subject'];
$node = array(
'type' => 'forum',
);
$node = (object) $node;
$form['preview_comment'] = array(
'#title' => t('Preview'),
'#value' => theme('comment', $comment, $node),
);
}
$comment_anonymous_forum = variable_get('comment_anonymous_forum', COMMENT_ANONYMOUS_MAYNOT_CONTACT);
if (!$user->uid && $comment_anonymous_forum != COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
drupal_add_js(drupal_get_path('module', 'comment') . '/comment.js');
}
if ($user->uid) {
$form['_author'] = array(
'#type' => 'item',
'#title' => t('Your name'),
'#value' => theme('username', $user),
);
$form['author'] = array(
'#type' => 'value',
'#value' => $user->name,
);
}
elseif ($comment_anonymous_forum == COMMENT_ANONYMOUS_MAY_CONTACT) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 60,
'#size' => 30,
'#default_value' => variable_get('anonymous', t('Anonymous')),
);
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#maxlength' => 64,
'#size' => 30,
'#description' => t('The content of this field is kept private and will not be shown publicly.'),
);
$form['homepage'] = array(
'#type' => 'textfield',
'#title' => t('Homepage'),
'#maxlength' => 255,
'#size' => 30,
);
}
elseif ($comment_anonymous_forum == COMMENT_ANONYMOUS_MUST_CONTACT) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 60,
'#size' => 30,
'#default_value' => variable_get('anonymous', t('Anonymous')),
'#required' => TRUE,
);
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#maxlength' => 64,
'#size' => 30,
'#description' => t('The content of this field is kept private and will not be shown publicly.'),
'#required' => TRUE,
);
$form['homepage'] = array(
'#type' => 'textfield',
'#title' => t('Homepage'),
'#maxlength' => 255,
'#size' => 30,
);
}
if (variable_get('comment_subject_field_forum', 1) == 1) {
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#maxlength' => 64,
);
}
$form['comment_filter']['comment'] = array(
'#type' => 'textarea',
'#title' => t('Comment'),
'#rows' => 15,
'#required' => TRUE,
);
$form['comment_filter']['format'] = filter_form(FILTER_FORMAT_DEFAULT);
$form['uid'] = array(
'#type' => 'value',
'#value' => $user->uid,
);
$form['discussthis_nid'] = array(
'#type' => 'value',
'#value' => $nid,
);
// Only show save button if preview is optional or if we are in preview mode.
// We show the save button in preview mode even if there are form errors so that
// optional form elements (e.g., captcha) can be updated in preview mode.
if ($is_ready || variable_get('comment_preview_forum', COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 19,
);
$form['#submit'][] = 'discussthis_create_form_submit';
}
$form['preview'] = array(
'#type' => 'button',
'#value' => t('Preview'),
'#weight' => 20,
);
return $form;
}