Form helper with Smarty

Derek Jones edited this page Jul 5, 2012 · 8 revisions
Clone this wiki locally


If you use Smarty as your template engine in CodeIgniter you may find this useful for generating form tags.


Regular form

{form url='module/function'}

    <input type="submit" />


Upload Form

{form url='module/function' type='upload'}

    <input type="submit" />



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.

Author: Svetoslav Marinov; svetoslavm []
Inspired by:

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();
    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();