-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Form helper with Smarty
If you use Smarty as your template engine in CodeIgniter you may find this useful for generating form tags.
Usage:
=Regular form=
[code] {form url='module/function'}
<input type="submit" />
{form} [/code]
Upload Form
[code] {form url='module/function' type='upload'}
<input type="submit" />
{form} [/code]
Note:
if you use {form} without the url parameter this will close the form.
Installation Create a file "function.form.php" in Smarty-x.y.z/libs/plugins where x.y.z are the version number of Smarty.
[code] <?php Author: Svetoslav Marinov; svetoslavm [] gmail.com Inspired by: http://codeigniter.com/wiki/Use_URL_helper_from_Smarty/ */
function smarty_function_form($params, &$smarty) { //check if the needed function exists //otherwise try to load it if (!function_exists('form_open')) { //return error message in case we can't get CI instance if (!function_exists('get_instance')) return "Can't get CI instance"; $CI= &get;_instance(); $CI->load->helper('form'); }
if (isset($params['url']) && $params['type'] == 'upload') {
return form_open_multipart($params['url']);
} elseif (isset($params['url'])) {
return form_open($params['url']);
} else {
return form_close();
}
} ?> [/code]