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 - 05-11-2009

[eluser]macigniter[/eluser]
@all

I have received some valuable feedback from some of you and will try to incorporate it in the next release of the library. I am also planning on finishing the user guide asap. There's just too much going on right now and this library is just a thing I am developing on the side.

Anyway, I appreciate any feedback or suggestions you have and would love to know if you use the library and what your experience is...


Form Generation Library - El Forum - 05-11-2009

[eluser]Robert May[/eluser]
[quote author="macigniter" date="1242068383"]@robert:

In order to make it work you need to submit the form to the same controller and then redirect from there. You cannot access $form->get() in the login() function, since you haven't instantiated the form object in that function.

Try this:

Code:
class Auth extends Controller {

    function Auth()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->session->keep_flashdata('refer');
        $this->load->library('form'); // first of all we have to load the library
        $form = new Form(); // then we instantiate a new form object
        
        $form // and fill it with elements
        ->open('auth')
        ->text('author_name', 'Username/email:', 'trim|alpha_numeric|max_length[255]|xss_clean')
        ->pass('author_password', 'Password:', 'trim|alpha_numeric|max_length[20]|xss_clean')
        ->reset()
        ->submit();

        $form->validate();  

        if ($form->valid) redirect('auth/login');

        $data['form'] = $form->get(); // this returns the validated form as a string
        $data['errors'] = $form->errors;  // this returns validation errors as a string
        
        $content    = $this->load->view('auth', $data, TRUE);
        
        $data        = array(
                            'page_title'    =>    'Login',
                            'sub_heading'    =>    'Please login to continue',
                            'content'        =>    $content,
                        );

        $this->templater->build($data);
    }
    
    function login()
    {
        // this is where you put the stuff that is shown when the user has successfully logged-in. don't forget to add an authentication here!
    }
[/quote]

Thanks muchly! That makes perfect sense now Smile


Form Generation Library - El Forum - 05-12-2009

[eluser]jcq[/eluser]
I've been following this project for a little while now and it shows great promise! I'm curious if there's a way to optionally specify additional tags to surround form elements for the purposes of styling. Looking through the documentation and the code I don't see that functionality, but perhaps I'm missing it.

Ideally, I'd like to be able to specify that I want LABEL/INPUT combos to be surrounded by an LI (or DIV, or whatever) tag, and that everything within a FIELDSET is contained within a UL, OL, DIV, etc. This would allow for much greater flexibility in creating styles for very accessible forms. Best case scenario would be to be able to specify it as a form-wide setting that can also be overridden on individual elements, but even just a form-wide config parameter would be quite helpful.

I envision something along the lines of setting a config variable (probably an array) that specifies a tag (or tags) to wrap or be contained within a given form element. After that, it's just a matter of automatically appending that tag (and corresponding closing tag) whenever the HTML is generated for the form element.

Thank you for all the work that you've done on this. It looks great!


Form Generation Library - El Forum - 05-12-2009

[eluser]IamPrototype[/eluser]
I FUCKING LOVE THIS MAN! DAMN, YOU'RE GREAT! Big Grin I've read the user guide and it all seems to easy and chill Smile I can't wait to use it and I'm looking forward for further versions/updates!


Form Generation Library - El Forum - 05-13-2009

[eluser]got 2 doodle[/eluser]
Great stuff here, just working through it to see it it's appropriate for a project

small bug here
Line 994 change $name to $nameid
Code:
function iupload($nameid, $label='', $required=FALSE, $atts=array())
    {
        $info = $this->_make_info($atts);
        if (!@$info['allowed_types']) $info['allowed_types'] = 'jpg|png|gif';
        $this->upload($nameid, $label, $required, $info);
        return $this;
    }

Having a problem with the upload function

A small error in the docs
Code:
$form->upload('file', 'Upload File', 'allowed_types=pdf|zip, max_size=4000')

should read
Code:
$this->form->upload('file', 'Upload File','','allowed_types=pdf|zip, max_size=4000');

note third passed parameter is missing in docs

Very very cool! can't wait to see the docs finished.

doodle


Form Generation Library - El Forum - 05-13-2009

[eluser]got 2 doodle[/eluser]
OK I'm baffled and I simply must move on to maintain my sanity, at least for now

Here is my controller (function within controller)

Code:
/****************************    restrict   **************************************/    

    function upload_data()

/*******************************************************************************/    

    {
$this->load->library('form'); // first of all we have to load the library

$form = new Form();
$_view = 'upload';


$form->open('/res/upload_data')
->text('text1|text1','Text')
->upload('file', 'Upload File','','allowed_types=csv, max_size=8000')
->submit()
->onsuccess('redirect', '/res/inventory');

// the next line just grabs some data and a menu (array) based on a named 'page'
// $this->prefix = 'res'

        $data =$this->get_pagedata($this->prefix.'_contact',$this->prefix.'_contact');


        $data['form'] = $form->get(); // this returns the validated form as a string
        $data['errors'] = $form->errors;  // this returns validation errors as a string

// the next line loads a collection of view segments
// ie. header + content + footer
// content would be replaced with the value of $_view

$this->load_views($data,$_view);

    }

Ok so cool the view shows the form. On success I just send it to another existing page but using the profiler I don't see any $_POST data.

I've tried ->onsuccess('redirect', '/res/upload_data'); with the same result

The bundled example works no problem.
Confusedhut:

Any ideas??
doodle


Form Generation Library - El Forum - 05-13-2009

[eluser]got 2 doodle[/eluser]
Nope, don't get it!
Code:
/****************************    restrict   **************************************/    

    function upload_data()

/*******************************************************************************/    

    {
$this->output->enable_profiler(TRUE);
$this->load->library('form'); // first of all we have to load the library

$form = new Form();
$_view = 'upload';


$form->open('/res/upload_data')
->text('text1|text1','Text')
->upload('file', 'Upload File','','allowed_types=csv, max_size=8000')
->submit()
->onsuccess('redirect', '/res/upload_success');

        //$data =$this->get_pagedata($this->prefix.'_contact',$this->prefix.'_contact');

        $data['form'] = $form->get(); // this returns the validated form as a string
        $data['errors'] = $form->errors;  // this returns validation errors as a string


//$this->load_views($data,$_view);
$this->load->view($_view,$data);

    }    

    function upload_success()

    {
$this->output->enable_profiler(TRUE);


        $this->load->view("upload_success");

    }

Even this paired down version, no $_POST data
:down:
doodle


Form Generation Library - El Forum - 05-14-2009

[eluser]got 2 doodle[/eluser]
Um..
a little more playing around and I think this lib is going to be really useful.

I uploaded a file with an ->upload control and it went to my defined folder all is well

but umm.. what happend to the $_POST data??

How can I retrieve the uploaded file name etc.?

I see about one hundred functions in the library, now I know why the documentation is unfinished.

I need a hint.. please

doodle


Form Generation Library - El Forum - 05-14-2009

[eluser]got 2 doodle[/eluser]
Ok, if I remove the ->onsuccess() then I get some $_POST data, it seems the redirect wipes out any $_POST data


Possible bug here.
If I define allowed_types=csv in the config file only I can upload anything I want, but if I define in the controller allowed_types=csv then I can only upload csv files.

doodle


Form Generation Library - El Forum - 05-19-2009

[eluser]macigniter[/eluser]
[quote author="jcq" date="1242168090"]I've been following this project for a little while now and it shows great promise! I'm curious if there's a way to optionally specify additional tags to surround form elements for the purposes of styling. Looking through the documentation and the code I don't see that functionality, but perhaps I'm missing it.

Ideally, I'd like to be able to specify that I want LABEL/INPUT combos to be surrounded by an LI (or DIV, or whatever) tag, and that everything within a FIELDSET is contained within a UL, OL, DIV, etc. This would allow for much greater flexibility in creating styles for very accessible forms. Best case scenario would be to be able to specify it as a form-wide setting that can also be overridden on individual elements, but even just a form-wide config parameter would be quite helpful.

I envision something along the lines of setting a config variable (probably an array) that specifies a tag (or tags) to wrap or be contained within a given form element. After that, it's just a matter of automatically appending that tag (and corresponding closing tag) whenever the HTML is generated for the form element.

Thank you for all the work that you've done on this. It looks great![/quote]

I will add it to my list! Thanks for your feedback.