From 9f543bb8999de2db20e71f9d5c7e1fdda13f29a8 Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 5 Dec 2010 19:41:42 +0000 Subject: Fixes #2616 Adds Evan's view form convenience function git-svn-id: http://code.elgg.org/elgg/trunk@7539 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/views.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'engine/lib/views.php') 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 @@ -1005,6 +1005,47 @@ function elgg_view_listing($icon, $info) { return elgg_view('entities/entity_listing', array('icon' => $icon, 'info' => $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
tag and inserts the anti-csrf security tokens. + * + * @example + * echo elgg_view_form('login'); + * + * 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: + * + * + * + * Then elgg_view_form('login') generates: + * + * ...security tokens... + * + * + *
+ * + * @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. * -- cgit v1.2.3