--- faq_ask.module Thu Oct 22 05:11:46 2009 +++ faq_ask.module Wed Nov 11 05:21:59 2009 @@ -132,8 +132,40 @@ /** * Get the ask question form. */ -function faq_ask_page($tid = NULL) { - drupal_goto('node/add/faq', 'ask=true'); +function faq_ask_page() { + + // we can't just call node_add(), + // because we don't want the access checking. + + global $user; + + // Initialize settings: + $node_array = array( + 'uid' => $user->uid, + 'name' => (isset($user->name) ? $user->name : ''), + 'type' => 'faq', + 'language' => '' + ); + + module_load_include('inc', 'node', 'node.pages'); + return drupal_get_form('faq_node_form', $node_array); +} + + +/** + * Disable undesired form elements + * that you are not supposed to see on a faq_ask page. + */ +function faq_ask_disable_form_elements(&$form) { + foreach (array( + 'revision_information', + 'path', + 'author', + 'options', + ) as $key) { + $form[$key]['#type']= 'value'; + } + return $form; } /** @@ -161,15 +193,15 @@ * Implementation of hook_form_alter(). * This is how we build the "ask question" form. */ -function faq_ask_form_alter(&$form, $form_state, $form_id) { - if ($form_id != 'faq_node_form' || !isset($_GET['ask'])) { - return; - } - if ($_GET['ask'] != 1 && $_GET['ask'] != 'true') { +function faq_ask_form_faq_node_form_alter(&$form, $form_state) { + + if (user_access('answer question') && $_GET['q'] != 'faq_ask') { return; } - - drupal_set_title(t('Ask a Question')); + + + $form['#after_build'][] = 'faq_ask_disable_form_elements'; + // Set the published field off and make sure they can't override it. $form['options']['status']['#default_value'] = FALSE; $form['options']['status']['#disabled'] = TRUE; @@ -181,10 +213,16 @@ if (variable_get('faq_ask_categorize', FALSE)) { unset($form['taxonomy']); } - $form['body'] = array('#type' => 'value', '#value' => variable_get('faq_ask_unanswered', t('Not answered yet.'))); + $form['body'] = array( + '#type' => 'value', + '#value' => variable_get('faq_ask_unanswered', t('Not answered yet.')) + ); // Make sure we know we came from here. - $form['faq_ask'] = array('#type' => 'value', '#value' => TRUE); + $form['faq_ask'] = array( + '#type' => 'value', + '#value' => TRUE + ); $form['#submit'][] = 'faq_ask_submit'; } @@ -865,7 +903,7 @@ case 1: // Ask a question block. if (user_access('ask question')) { - $block['content'] = faq_ask_page(NULL); + $block['content'] = faq_ask_block_content(); } } // end switch($delta).