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 - 09-24-2009

[eluser]groyk[/eluser]
I have solved it by running my function direct from "users/edit" and then redirect. It is just for a simple login.

Code:
# Login form
            $this->form->open('users/login','login')
                ->html('<p>')
                ->text('username','Username','required|min_length[3]')
                ->password('password','Password','required')
                ->submit('Login')//,$del_att)
                ->html('</p>');
                ;
                
                
                if(isset($_POST['username'])) {
                    if($this->userlib->login($_POST['username'],$_POST['password'])) {
                        redirect($redirect);
                    } else {
                        $error = '<div style="color: #c00">- Wrong username or password</div>';
                    }                    
                }
                
                $this->form->validate();
                $this->form->get();
                
                            
                $data['form'] = $this->form->get_array();
                $data['errors'] = $this->form->errors;



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

[eluser]hugle[/eluser]
[quote author="macigniter" date="1253238090"]BTW... anyone still interested in helping to complete the user guide? I am just too busy at the moment but nevertheless would love the guide to be complete. So if you are using the library for a while now and feel confident enought to contribute your help will be greatly appreciated![/quote]


Hello, I use your library only for two days (just looking at it, testing, etc)
But I feel start to love it Smile
I could write some basic text, but I'm not english Wink)

I saw peaople have some problems with uploads, I think when I'm done with it - I could add some information to howto.

now the problem is, if I even add required false, like:
Code:
->upload('file', 'Upload Image', false)
I still get:
- The upload path does not appear to be valid.

Imho, the upload path shouldn't be checked... if there is no 'required' ...

[edited]
confirmed, if I do for example:
Code:
$upload = array(
           'upload_path' => '/var/www/vhosts/invista.lt/subdomains/demo/httpdocs/test',
           'max_size'    => '20000',
           'allowed_types' => 'pdf|zip',
           'max_size' => 4000
        );
        
.....
and later:
->upload('file', 'Upload File', false, $upload)

Everything works just fine!
[end of edit]

thanks!Smile


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

[eluser]hugle[/eluser]
Hello everyone,
I think I'll start from the BUG maybe, i found .... Ireally hope it isn't
but then I must be doing something really wrongSad

So I'll start.... my controller:
Code:
$this->form->open('profile/post_ad')
->text('interest_rate', 'interest_rate', 'required|test1', '', 'class="text"')
->submit('Submit')
->model('Ads', 'post_ad')
->onsuccess('header', 'Location: /profile/success');

I have also extended the form_validation class, with:
Code:
function test1($str) { return 'test1_string'; }

my model ads.php is:
Code:
function post_ad(&$form, $post_data)
{
          echo '<pre>';
          print_r($post_data);
          echo '</pre>';  
}

the strange thing is ... that output I should get from model should be : 'test1_string'
since test1 rule returns it...

but output I get is always the value I put into form field...
I think something somewehre should be worng or I am doing somthing wrong

I thought maybe the function `test1` wasn't called - but I added echo there, and
it is working

Maybe some of you met similar problems and have some ideas?
I really like this library, it saves like lot of hours of creating labels etcSmile

Hope that helps you to understand my problem, and maybe help me fixing it.. thanksSmile

[edit]
I also wanted to add, that I was doing tests with basic form_validation with the same rules, and the result I got was
'test1_string'
[/edit]

cheers,
huglester


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

[eluser]Mat-Moo[/eluser]
Damn dude, 10/10 this is an awesome library! Most my CI projects have required only small forms, and although I've written helpers the forms have never been worthy of a library. Today I find myself working of several forms with lots of fields and started to modify my code to basically do what you are doing. Before working hard on this, I had a quick look through the CI forums and found this! So far I've already done one form, and I'm still learning this fantastic library! I've a lot to learn but I believe to date this will be the best ever 3rd party library for me!


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

[eluser]Paul T[/eluser]
So glad to see the continued development of this awesome library. I can't imagine building forms without it!

Good work on the reCAPTCHA function. One problem, though. It seems that at least some (all?) spam bots do not have javascript. In this case, the reCAPTCHA reverts to using an iframe which is not required, thereby defeating/bypassing the spam protection of the form. I'd love to see a fix for this. In the meantime, I'm going to have to make my javascript "obtrusive."

Oh, another thing. We upgraded our PHP to 5.3, which deprecates the split function found in various places in libraries/Form.php. Simply changing "split" to "explode" fixes it.

Keep up the great work!


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

[eluser]hugle[/eluser]
Hello again Smile
I must agree to both of you guys,
I have one bug, but author now is busy with some project to answer with questions.
Maybe someone of you wanna play and try to find a fix for that, to help develop this nice FORM application?Smile


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

[eluser]dinhtrung[/eluser]
After 2 hours code and F5, I found Form Generation very useful, but lack some major feature, especially the callback validation.
So here is my experience with Form Generation.
- If you want the form to show up an error, just use $form->add_error('field', 'message'). Because the lack of documentation, I spent more than an hour to use $form->set_error() or $form->set_error_label(). My mistake to not read the code carefully :">
- For callback feature, do it in the ($this->valid) block.
So for a real example: Authenticate using dx_auth, Template library and Form Generation library:
In controller (./applications/controllers/user.php)
Code:
function login()
    {    
        if (! $this->dx_auth->is_logged_in()){
            $this->load->library('form'); // first of all we have to load the library
            $this->form // then we fill the form with elements
            ->open('user/login')        
            ->fieldset("User Login")
            ->text('username', 'Your Username', 'required|trim|alpha_numeric|max_length[30]|xss_clean')
            ->pass('password', 'Your Password', 'required|trim|alpha_numeric|max_length[20]|xss_clean')            
            ->checkbox('loggedin', 'yes', 'I want to stay logged-in')
            ->fieldset()
            ->submit()
            ->reset()
            ->validate();


            $showform = TRUE;
            if ($this->form->valid){
                $tmp = $this->form->get_post();
                if (! $this->dx_auth->login($tmp["username"], $tmp["password"], $tmp["getloggedin"]))
                    $this->form->add_error("password", $this->dx_auth->get_auth_error());
                else $showform = FALSE;
            }

            if ($showform){
                $data['form'] = $this->form->get(); // this returns the validated form as a string
                $data['errors'] = $this->form->errors;  // this returns validation errors as a string
                $this->template->write_view('content', 'login', $data);
            } else
                $this->template->write('content', 'You are already logged in!');
            $this->template->render();
        } else
            redirect("user/dashboard");
    }
Note: in this example, I use $showform as a flag to render the form or not. If the user is successfully logged in, then we don't need to show the form. Instead, write "You are already logged in!" in the view and show that message to the user. This page should be automatically refresh into another page, through the meta tags at header.
- For view, I use the default of Form Generation: applications/views/login.php
Code:
<h3>Login</h3>
&lt;?php echo $errors; ?&gt;
&lt;?php echo $form; ?&gt;
Hope this will help new users save some time...


Form Generation Library - El Forum - 10-22-2009

[eluser]Mat-Moo[/eluser]
In the break_after, I was trying to get radiogroups to work, but I can only seem to get radio to work and ot radiobuttons. What and I missing?


Form Generation Library - El Forum - 10-22-2009

[eluser]hugle[/eluser]
[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


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

[eluser]wiredesignz[/eluser]
@macigniter, You've done a great job with this, It's really quite impressive. Thanks.

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. You might like to consider something similar (for regular CI) added directly to the class.

Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Form Generation library extension for Modular extensions - PHP5
*
* Form class is loaded via spl_autoload
**/
class MX_Form extends Form
{
    function __construct() {
        parent::Form();
        
        $this->form = $this;
    }
    
    function __toString()
    {
        return $this->get();
    }
    
    function load($form, $data = NULL, $return = FALSE)
    {        
        $module = CI::$APP->router->fetch_module();
        list($path, $file) = Modules::find($form, $module, $this->config['directory']);
        
        if (is_array($data)) extract($data);
        include($path.$file.EXT);
        
        return ($return) ? $this->get() : $this;
    }    
}

Controller code
Code:
$this->load->library('mx_form', '', 'form');

$data['form'] = $this->form->load('setting_frm', $data, TRUE);