aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-05 19:41:42 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-05 19:41:42 +0000
commit9f543bb8999de2db20e71f9d5c7e1fdda13f29a8 (patch)
tree277d606973fadce7702c7604443cf76065100f88
parented81771d23473786d1fb43bae0ea5ca7f0b441ad (diff)
downloadelgg-9f543bb8999de2db20e71f9d5c7e1fdda13f29a8.tar.gz
elgg-9f543bb8999de2db20e71f9d5c7e1fdda13f29a8.tar.bz2
Fixes #2616 Adds Evan's view form convenience function
git-svn-id: http://code.elgg.org/elgg/trunk@7539 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/views.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/engine/lib/views.php b/engine/lib/views.php
index 70b4b833d..5d7c21002 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -1006,6 +1006,47 @@ function elgg_view_listing($icon, $info) {
}
/**
+ * Convenience function for generating a form from a view in a standard location.
+ *
+ * This function assumes that the body of the form is located at "forms/$action" and
+ * sets the action by default to "action/$action". Automatically wraps the forms/$action
+ * view with a <form> tag and inserts the anti-csrf security tokens.
+ *
+ * @example
+ * <code>echo elgg_view_form('login');</code>
+ *
+ * This would assume a "login" form body to be at "forms/login" and would set the action
+ * of the form to "http://yoursite.com/action/login".
+ *
+ * If elgg_view('forms/login') is:
+ * <input type="text" name="username" />
+ * <input type="password" name="password" />
+ *
+ * Then elgg_view_form('login') generates:
+ * <form action="http://yoursite.com/action/login" method="POST">
+ * ...security tokens...
+ * <input type="text" name="username" />
+ * <input type="password" name="password" />
+ * </form>
+ *
+ * @param string $action The name of the action (without the leading "action/") -- e.g. "login"
+ * @param array $form_vars $vars environment passed to the "input/form" view
+ * @param array $body_vars $vars environment passed to the "forms/$action" view
+ *
+ * @return string The complete form
+ */
+function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {
+ global $CONFIG;
+
+ $defaults = array(
+ 'action' => $CONFIG->wwwroot . "action/$action",
+ 'body' => elgg_view("forms/$action", $body_vars),
+ );
+
+ return elgg_view('input/form', array_merge($defaults, $form_vars));
+}
+
+/**
* Registers a function to handle templates.
*
* Alternative template handlers can be registered to handle