All pastes #730729 Raw Edit

Etwas

public text v1 · immutable
·published 2007-10-09 13:37 UTC
rendered paste body
// 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 = "<div id=\"mars_question\">";
      $output .= "<div id=\"close_mars_question\"><a href=\"#\" onclick=\"$('#mars_question').hide(); return false;\">X</a></div>";
      $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 .= "</div>";
    }
  }
  return $output;
}