CodeIgniter Forums
Form Generation Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Form Generation Library (/showthread.php?tid=16439)



Form Generation Library - El Forum - 06-17-2009

[eluser]Robert May[/eluser]
Just set up a fresh CI install, going to get to work on it!
It's going to be a part of my planned CI CMS, as it would save me acres of time in the long run!

Currently planned features:

Basic admin panel
Form generator must be able to create forms that can be parsed into templates
Designed to work wherever you want it, including the admin area
User restrictions on where a form can be used (prevent from putting an add content form on the homepage, for example)
Creates a DB table for each form, effectively building the CMS DB
Stores all variables for the form library in the DB, including validation

Now, I can't guarantee that this will be built quickly, or completed, as my attention span can wilt from time to time, but I'm enthusiastic about it as it'll save me time in future projects! Wink

And @got 2 doodle, I've been thinking of making it more admin-based for creating a CMS. The form generator could be hidden from the end-user. It's an awesome feature of Symphony CMS that I saw recently, and I'd like to make a more general one for CI use.


Form Generation Library - El Forum - 06-17-2009

[eluser]got 2 doodle[/eluser]
@macigniter

is the multiple config files working? or am I doing something wrong

in config file

Code:
$nameasid[1] = TRUE;
$replace[1] = 'FALSE|TRUE|TRUE';
...etc....
$defaults[1] = array(
    'label' => array(    // this applies to all labels
        'class' => 'left'
    ),
..etc...
    // always define defaults for specific elements (below) after defaults by element type (above)
    'multiple' => array(
        'style' => 'height: 120px'
    )
);

in controller

Code:
$form = new Form();

        $form
        ->config(1)
        ->open($this->prefix.'/form1')

gives me 'undefined index' errors here

libraries/Form.php

Line Number: 733 - 761

Code:
$this->config['globals'] = (array_key_exists(1, $globals)) ? $globals[$key] : $globals;
$this->config['defaults'] = (array_key_exists(1, $defaults)) ? $defaults[$key] : $defaults;
$this->config['replace'] = (is_array($replace)) ? $replace[$key] : $replace;
...etc...

any thoughts?

doodle


Form Generation Library - El Forum - 06-17-2009

[eluser]Paul T[/eluser]
[quote author="macigniter" date="1245159910"]Hi Paul, can you please forward your mods to the library (please send to info (at) frankmichel (dot) com) so I can take a look and integrate it into future versions? Maybe I can come up with a solution to that usability issue...[/quote]

Sent you an email.


Form Generation Library - El Forum - 06-17-2009

[eluser]got 2 doodle[/eluser]
@macigniter

got the multiple configs working for now

in library Form.php
Code:
function Form()
    {
        // set CI instance
        $this->CI =& get_instance();
        $this->CI->load->helper('form');
        //$this->config();
    }
in controller
Code:
$form = new Form();

        $form
        ->config(1)  <--- if you comment out this line it will error
        ->open($this->prefix.'/form1')

You must call the config() method but it's a hack that works for me now.

If you don't comment out $this->config then the value never gets passed

doodle


Form Generation Library - El Forum - 06-17-2009

[eluser]macigniter[/eluser]
[quote author="got 2 doodle" date="1245263841"]@macigniter

is the multiple config files working? or am I doing something wrong

any thoughts?

doodle[/quote]

I fixed this. Please substitute the config function in Form.php with this one:

Code:
/**
     * Config
     *
     * Writes configuration values into config array
     */    
    function config($key=NULL)
    {
        if (!defined('FGL_ERR')) define('FGL_ERR', '<b>Form Generation Library</b><br />');
        
        if (is_file(APPPATH."config/form.php"))
        {
            include(APPPATH."config/form.php");
            
            // settings used in EL class
            $this->config['globals'] = (isset($key) && array_key_exists($key, $globals)) ? $globals[$key] : $globals;
            $this->config['defaults'] = (isset($key) && array_key_exists($key, $defaults)) ? $defaults[$key] : $defaults;

            $this->config['replace'] = (isset($key) && is_array($replace) && array_key_exists($key, $replace)) ? $replace[$key] : $replace;
            $this->config['nameasid'] = (isset($key) && is_array($nameasid) && array_key_exists($key, $nameasid)) ? $nameasid[$key] : $nameasid;

            $this->config['label_pos'] = (isset($key) && is_array($label_pos) && array_key_exists($key, $label_pos)) ? $label_pos[$key] : $label_pos;
            $this->config['label_req_class'] = (isset($key) && is_array($label_req_class) && array_key_exists($key, $label_req_class)) ? $label_req_class[$key] : $label_req_class;
            $this->config['label_req_flag'] = (isset($key) && is_array($label_req_flag) && array_key_exists($key, $label_req_flag)) ? $label_req_flag[$key] : $label_req_flag;            

            $this->config['error_inline'] = (isset($key) && is_array($error_inline) && array_key_exists($key, $error_inline)) ? $error_inline[$key] : $error_inline;
            $this->config['error_inline_open'] = (isset($key) && is_array($error_inline_open) && array_key_exists($key, $error_inline_open)) ? $error_inline_open[$key] : $error_inline_open;
            $this->config['error_inline_close'] = (isset($key) && is_array($error_inline_close) && array_key_exists($key, $error_inline_close)) ? $error_inline_close[$key] : $error_inline_close;
    
            $this->config['error_flag'] = (isset($key) && is_array($error_flag) && array_key_exists($key, $error_flag)) ? $error_flag[$key] : $error_flag;
            
            // settings used in FORM class
            $error_open = (isset($key) && is_array($error_open) && array_key_exists($key, $error_open)) ? $error_open[$key] : $error_open;
            if ($error_open) $this->error_open = $error_open;
            
            $error_close = (isset($key) && is_array($error_close) && array_key_exists($key, $error_close)) ? $error_close[$key] : $error_close;
            if ($error_close) $this->error_close = $error_close;
                
            $this->error_string_open = (isset($key) && is_array($error_string_open) && array_key_exists($key, $error_string_open)) ? $error_string_open[$key] : $error_string_open;
            $this->error_string_close = (isset($key) && is_array($error_string_close) && array_key_exists($key, $error_string_close)) ? $error_string_close[$key] : $error_string_close;
    
            $this->error_class = (isset($key) && is_array($error_class) && array_key_exists($key, $error_class)) ? $error_class[$key] : $error_class;

            $break_after = (isset($key) && is_array($break_after) && array_key_exists($key, $break_after)) ? $break_after[$key] : $break_after;
            if (is_string($break_after)) $this->break_after = explode('|', $break_after);
        }
        else
        {
            show_error(FGL_ERR.'Config file could not be loaded.');
        }

        return $this;        
    }

I will include this in the next version and upload tomorrow. I am also working on some other minor improvements in the config() function.


Form Generation Library - El Forum - 06-17-2009

[eluser]got 2 doodle[/eluser]
@macigniter

Excellent, thank you it works!

:coolsmile: <--- look at that happy face!

doodle


Form Generation Library - El Forum - 06-17-2009

[eluser]macigniter[/eluser]
[quote author="got 2 doodle" date="1245259936"]
Quote:it would be pretty easy to implement database-created forms using this library

@Robert May

That's cool, I had exactly the same thought but I'm not convinced that it would save any time, but it would be a cool feature to include in a cms.

I don't think processing would be too hard, the table could include
- table name
- field name
- type of control
- action

But when I got to thinking about how to process the form, I started wondering who would benefit. Usually end users are freaked out by editing a text field. I don't know how they would do with creating their own forms. At best the forms would have to be minimal.

doodle[/quote]

I think a great contribution to this library would be an "online form builder" for the form generation library. To save all of us programmers (not for the end-user) some typing and just let us click our forms together and then spit out the form generation library code that we can just copy and paste into our controller.

Just a thought...


Form Generation Library - El Forum - 06-17-2009

[eluser]Robert May[/eluser]
That could be a useful by-product of what I had planned actually. That will prove quite easy methinks, and I could optionally have it generate the SQL for a relevant table for the form. It shouldn't actually take too long to come up with that.

I can't seem to find a list of all available options for the library, is there any chance you could list all validation options and field types? That way I can stick them in select boxes! Wink


Form Generation Library - El Forum - 06-18-2009

[eluser]Cyclops[/eluser]
Hey, Mr FormGenLib,

Great work! A framework should not be without a library like this.

One quick question:
Is there a way to define validation rules in a file, or in an array somewhere, and then have the $form object load the specified rules up for each specific form? This would be very nice if similar forms will be used in more than one place (like as in create / edit / ajaxEdit, etc).

Any help would be great Smile


Form Generation Library - El Forum - 06-24-2009

[eluser]bEz[/eluser]
@cyclops
Are you referring to defined validation rules by way of a ruleset, and in a config file?
for instance: (off the top of me head)
Code:
$config['form_rule_set] = array (
    super_strict => 'trim|required|alpha_slash|max_length[10]|xss_clean',
    not_as_strict => 'trim|required|alpha_slash',
    just_tidy => 'trim|required'
);