// Random Mars question function mars_question() { if (arg(0) == "mysite" && arg(3) == "new") { if (isset($_POST['form_id'])) { $form_id = $_POST['form_id']; $question = str_replace("_node_form","", $form_id); $node = array("type" => $question); $form = drupal_retrieve_form($form_id, $node); drupal_prepare_form($form_id, $form); drupal_validate_form($form_id, $form); drupal_submit_form($form_id, $form); drupal_get_messages(); drupal_goto(arg(0) . "/" . arg(1) . "/" . arg(2)); } elseif (rand(1,5) == 1) { //Content type of question. Could be extended to select a random question. $question = "mars_question_1"; $output = "
"; $output .= "
X
"; $node = array("type" => $question); $form_id = $question . "_node_form"; $form = drupal_retrieve_form($form_id, $node); drupal_prepare_form($form_id, $form); unset($form['preview']); $output .= drupal_render_form($form_id, $form); //$output .= print_r($form, TRUE); $output .= "
"; } } return $output; }