function fp_render_form

6.x render.inc fp_render_form($callback, $form_type = "")
4.x forms.inc fp_render_form($callback, $form_type = "")
5.x render.inc fp_render_form($callback, $form_type = "")

Render the form array from the callback to the screen, and set the form to save itself in our default submit handler. Valid form_types are: "system_settings" => values automatically saved to variables table. "normal" or BLANK => values are forwarded to $callback_submit() function, if it exists.

4 calls to fp_render_form()
comments_display_main in modules/comments/comments.module
This displays the primary Comments tab, where we see past comments and can enter a new one (with the right permissions).
hook_render_block in modules/blocks/blocks.module
Example of hook_render_block
system_display_login_page in modules/system/system.module
Display the "login" page. This is the default page displayed to the user, at /login, if they have not logged in yet.
system_render_block in modules/system/system.module

File

includes/forms.inc, line 112

Code

function fp_render_form($callback, $form_type = "") {
  global $current_student_id, $user;
  $rtn = "";

  // Were there extra params after callback and form_type?  Wrap them up
  // and send them along to fp_get_form
  $params = array();
  if (func_num_args() > 2) {
    // Remove first 2 arguments, so all we have left is what the user added to it.
    $params = func_get_args();
    array_shift($params);
    array_shift($params);
  }

  $form = fp_get_form($callback, $params);

  // Figure out the current page's title and display it.
  $path = $_GET ["q"];
  $default_path = $path;
  // Figure out the "default_query" from $_GET
  $new_query = array();
  foreach ($_GET as $key => $val) {
    if ($key != "q") {
      $new_query [] = "$key=$val";
    }
  }
  if (count($new_query)) {
    $default_query = join("&", $new_query);
  }

  $page_title = $GLOBALS ["fp_current_menu_router_item"]["title"];
  if (isset($GLOBALS ["fp_set_title"])) {
    $page_title = $GLOBALS ["fp_set_title"];
  }

  if ($page_title != "") {
    $rtn .= "<h2 class='title'>" . $page_title . "</h2>";
  }

  //fpm($GLOBALS["fp_current_menu_router_item"]);
  $form_path = $GLOBALS ["fp_current_menu_router_item"]["path"];

  // Are there any files required to get to the submit handler for this form?
  $form_include = "";
  // Set the form_include to the current page's "file" requirement, if any.
  if (is_array($GLOBALS ["fp_current_menu_router_item"])) {
    if (isset($GLOBALS ["fp_current_menu_router_item"]["file"])) {
      $form_include = $GLOBALS ["fp_current_menu_router_item"]["file"];
    }
  }
  if ($form ["#form_include"]) {
    $form_include = $form ["#form_include"];
  }

  $extra_form_class = "";
  if ($form_type == "system_settings") {
    $extra_form_class = "fp-system-form";
  }

  $form_token = md5($callback . fp_token());

  // Set up our form's attributes.
  $attributes = $form ["#attributes"];
  if (!is_array($attributes)) {
    $attributes = array();
  }

  $attributes ["class"] .= " $extra_form_class fp-form fp-form-$callback ";
  // Convert the attributes array into a string.
  $new_attr = "";
  foreach ($attributes as $key => $val) {
    $new_attr .= " $key='$val' ";
  }
  $attributes = $new_attr;

  // Did the user specify a submit method (like GET or POST)?  POST is default.
  $submit_method = ($form ["#submit_method"] == "") ? "POST" : $form ["#submit_method"];

  $rtn .= "<form action='" . base_path() . "/system-handle-form-submit' method='$submit_method' id='fp-form-$callback' name='fp_form_name_$callback' $attributes>";

  $rtn .= "<input type='hidden' name='callback' value='$callback'>";
  $rtn .= "<input type='hidden' name='form_token' value='$form_token'>";
  $rtn .= "<input type='hidden' name='form_type' value='$form_type'>";
  $rtn .= "<input type='hidden' name='form_path' value='$form_path'>";
  $rtn .= "<input type='hidden' name='form_include' value='$form_include'>";
  $rtn .= "<input type='hidden' name='default_redirect_path' value='$default_path'>";
  $rtn .= "<input type='hidden' name='default_redirect_query' value='$default_query'>";
  //$rtn .= "<input type='hidden' name='redirect_query' value='$redirect_query'>";
  $rtn .= "<input type='hidden' name='current_student_id' value='$current_student_id'>";

  $use_callback = "";
  if (form_has_errors()) {
    // We will only pull previous POST's values if there are errors on the form.
    $use_callback = $callback;
  }

  foreach ($form as $name => $element) {
    if (is_array($element) && (isset($element ["type"]) || isset($element ["value"]))) {
      $rtn .= fp_render_form_element($name, $element, $use_callback);
    }
  }


  // If this is a system settings form, go ahead and display the save button.
  if ($form_type == "system_settings") {
    $rtn .= "<div class='buttons'>";
    //$rtn .= fp_render_button("Save settings", "\$(\"#sysform\").submit()");
    $rtn .= "<input type='submit' name='submit_button' value='" . t("Save settings") . "'>";
    $rtn .= "</div>";
  }


  $rtn .= "</form>";


  // Clear any existing form errors and values
  unset($_SESSION ["fp_form_errors"]);
  clear_session_form_values($callback);

  return $rtn;

}