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

[eluser]macigniter[/eluser]
Hi Everyone!

Sorry for having been absent for quite a while. I have been terribly busy with a project and am just now returning to life as usual. I will go through all the posts and replies and hopefully release the much anticipated next version of the lib soon.

Stay tuned!


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

[eluser]hugle[/eluser]
[quote author="macigniter" date="1257132765"]Hi Everyone!

Sorry for having been absent for quite a while. I have been terribly busy with a project and am just now returning to life as usual. I will go through all the posts and replies and hopefully release the much anticipated next version of the lib soon.

Stay tuned![/quote]

HelloSmile

Nice to hear you are back Smile

How is your project going on? did you already finish it? or some major things left to be done?Smile


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

[eluser]seanloving[/eluser]
[quote author="wiredesignz" date="1256411819"]
Creating forms as partials and being able to load them using your class may be beneficial to others so I submit this PHP5 extension that I am using with Modular Extensions - PHP5, to give you an idea of what is possible with this library. [/quote]

@wiredesignz - thanks, I was wondering how to combine these libraries. I'm trying to get started as you suggest...

1- Is it correct to define
Code:
$this->config['directory'] = 'modules/'
inside the application/config/form.php file? The right value? The right place to define it?

2- Is this a proper looking directory and file structure?

Code:
mysite
  application
    libraries
      Form.php
      MX_Form.php
    modules
      keywords
        controllers
            keywords.php
        models
        views
            keywords.php (view)
            keyword_upload_form.php (view partial)
3 - What's the proper usage? Am I supposed to move the form generation code to the view partial views/keyword_upload_form.php ? or keep it in the controllers/keywords.php ?

Code:
$this->form->open('keyword_upload_form')
            ->fieldset('Upload Your Keyword List as a .CSV File')
            ->text('username', 'User Name', 'required|trim|max_length[40]')
            ->password('password', 'Password', 'required|trim|max_length[40]')
            ->upload('csv', 'Upload CSV')
            ->indent(15)
            ->submit('Upload', 'sub')
            ->margin(40);
[/code]

4 - Something not working in my initial setup. I'm getting the following warning.
Code:
Message: include(keyword_upload_form.php) [function.include]: failed to open stream: No such file or directory.

Line 26 of libraries/MX_Form.php
Any suggestions where to look?

Thanks
--Sean Loving


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

[eluser]clip[/eluser]
[quote author="hugle" date="1256267142"][quote author="macigniter" date="1253068962"][quote author="groyk" date="1252946144"]
One of my controllers contains multiply forms. In the form generator I need something like
Code:
$this->form->destroy();

Else when I call
Code:
$this->form->open('my_form')

I still get the output from the first.
[/quote]

This will be available in the next version! I will hope to release it soon. If you need that function instantly, feel free to insert this code right after the Form() function:

Code:
function flush()
    {
        $this->fieldsets = 0;
        $this->indented = 0;
        $this->columns = 0;
        
        $this->action = '';
        $this->method = 'post';
        $this->multipart = FALSE;
        $this->atts = array();
    
        $this->_elements = array();
        $this->_labels = array();
        $this->_aliases = array();
        $this->_names = array();
    
        $this->_last_accessed = '';
        $this->_output = '';
    
        $this->_submit_name = array();
        $this->_posted = FALSE;
            
        $this->_files = array();
        $this->_data = array();
    
        $this->_onsuccess = array();
        $this->_postprocess = array();
            
        $this->error = array();
        $this->errors = '';
        
        $this->error_string = '';
    
        $this->model = '';
        $this->model_method = '';
        $this->model_data = '';
        
        $this->valid = FALSE;
        $this->validated = FALSE;
        
        $this->recaptcha = FALSE;
        $this->recaptcha_error = '';    
    }

You can then use:

Code:
$this->form->flush();

in between two forms in the same controller. Don't forget to clear out the $data['form'] and/or $data['errors'] variables.[/quote]

thank you. it helped me Smile

by the way, maybe some of you tried passing some options to select,
to make some of options 'disabled'?

of maybe you have suggestions how this can be done?
thank you! Smile[/quote]

Alternatively if you have multiple forms you could just create opjects for each form:

Code:
$this->load->library('form');
$form_one = new $this->form();
$form_one->open('controller/method')
->text('etc'...)
->submit();

$form_two = new $this->form();
$form_two->open('controller/method')
->text('etc'..)
->submit();

$data['form_one_output'] = $form_one->get();
$data['form_one_errors'] = $form_one->errors;

$data['form_two_output'] = $form_two->get();
.....



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

[eluser]hugle[/eluser]
Quote:Alternatively if you have multiple forms you could just create opjects for each form:

Code:
$this->load->library('form');
$form_one = new $this->form();
$form_one->open('controller/method')
->text('etc'...)
->submit();

$form_two = new $this->form();
$form_two->open('controller/method')
->text('etc'..)
->submit();

$data['form_one_output'] = $form_one->get();
$data['form_one_errors'] = $form_one->errors;

$data['form_two_output'] = $form_two->get();
.....

Hello!

what a great solution alsoSmile
thanks a lot for your ideas!

huglester


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

[eluser]seanloving[/eluser]
[quote author="clip" date="1257380949"]

Alternatively if you have multiple forms you could just create opjects for each form:

Code:
$this->load->library('form');
$form_one = new $this->form();
$form_one->open('controller/method')
->text('etc'...)
->submit();

$form_two = new $this->form();
$form_two->open('controller/method')
->text('etc'..)
->submit();

$data['form_one_output'] = $form_one->get();
$data['form_one_errors'] = $form_one->errors;

$data['form_two_output'] = $form_two->get();
.....
[/quote]

I like this idea too. Just takes more memory, right? No other implications.
-SL


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

[eluser]hugle[/eluser]
Hello everyone,

wanted to ask if there is any follow up on the upload class..?

I'm able only to upload threw the Model, since in the controller the UPLOAD is empty...
I have no file names, nothing ...

How I can pass the data from the model back to the controller?
Or maybe someone already written some extends to fix this behavior?

Thank you !


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

[eluser]hugle[/eluser]
Hello everyone again,

I have found a little bug in Form library, I think, I'll explain:
I have simple form:
Code:
print_r($_POST);
    
        $this->form->open('/welcome/test')
        ->fieldset('Enter keywords to search for')
        ->text('search', 'Keywords:', '')->indent(150)
        ->submit('Submit')
        ->validate();
        
        if ($this->form->valid)
        {
            $post_data= array();
            $post_data = $this->form->get_post();
            print_r($post_data);
        }
And if I enter '&DEV;_0887&' as a search value(without quotes), and press submit, I get malicious data:
&DEV;_0887& becomes &DEV;_0887&

As you can see I'm not using any rules, but If I try to access $_POST before `if ($this->form->valid)` I have correct value = &DEV;_0887&.
Even $_POST inside if ($this->form->valid) has malicous data = &DEV;_0887&

I could not reproduce the bug... maybe some of you came to this problem?

Thank you!


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

[eluser]Maglok[/eluser]
This library seems very interesting. In your docs you mention PHP4 can handle it, yet PHP4 seems to die on me when I do so. I think it's in the constructor of the Form class itself, PHP4 just doesn't seem to play well with get_instance().

I'll have access to a PHP5 server soon enough and will check it all out then. Very nice regardless!


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

[eluser]score[/eluser]
Hey! Im a total noob to CI and kinda fresh with OOPHP also. I am trying to create a simple sign up form and put the entered data into a database.

Could someone point me in the right direction here? The form below works, but I do not know where to put the "insert in to database code"

I would also like help on creating a function for checking if the email exists in the database.

CODE:
Code:
<?php

class Welcome extends Controller {

    function Welcome(){
        parent::Controller();
        $this->load->helper('url');    
    }
    
    function index(){
        $this->load->library('form');
        $this->form
        ->open('welcome')
        ->text('firstName','First name', 'trim|required|xss_clean')
        ->text('lastName','Last name', 'trim|required|xss_clean')
        ->text('email','email','trim|required|xss_clean|valid_email')
        ->submit()
        ->onsuccess('redirect', 'welcome/success');
        
        $data['form'] = $this->form->get();
        
        
        $this->load->view('signup_form', $data);
    }
    
    function success(){
        $this->load->view('success');
    }
    
}