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 - 01-31-2011

[eluser]Maglok[/eluser]
Greetings people of the awesome form gen lib thread.

I have a question.

There is a clear() function to define two forms. Awesome.

Is there a way to detect which one gets submitted without the errors entangling?

I got a wip webapp here: http://pona.dev.fss.uu.nl/
It allows you to login or to register on the same page.

I have this as form generation code:
Code:
// Build new user form
        $this->config->load('pona');
        $faculties = $this->config->item('pona_faculties');
        
        $this->form
            ->text('new_email', 'Email address', 'required|valid_email')
            ->select('faculty', $faculties, 'Faculty', '1', 'required')
            ->hidden('type', 'new')
            ->submit('Create account')
            ->add_class('ui-state-default ui-corner-all');

        $data['form_new'] = $this->form->get();

        $this->form->clear();

        // Build existing user form
        $this->form
            ->text('email', 'Email address', 'required|valid_email')
            ->password('password', 'Password', 'required')
            ->checkbox('remember', '1', 'Remember me', FALSE, 'trim|xss_clean')
            ->hidden('type', 'login')
            ->html('<br/>')
            ->submit('Login')
            ->add_class('ui-state-default ui-corner-all');

        $data['form_login'] = $this->form->get();

That works.

But it is the handling of said forms. I have tried messing with it a bit, but I can't seem to get the errors to not highlight everything when the input is wrong, nor is this very neat. The docs aren't complete on the valid function. I basically need to be able to validate each form seperately instead of $this->form->valid.

Code:
// Decide what form is being submitted
        if(!isset($_POST['type'])) {
            echo "Its not submitted!";
        } elseif($_POST['type'] == 'login') {
            // It is the login form
            if ($this->form->valid)    {
                $post = $this->form->get_post(TRUE);
                $remember = $post->remember;

                if($this->ion_auth->login($this->input->post('email'), $this->input->post('password'), $remember)) {
                    // Login is successful
                    $this->session->set_flashdata('bericht', $this->ion_auth->messages());
                    redirect('current', 'refresh');
                } else {
                    // Login is unsuccessful
                    $this->session->set_flashdata('message', $this->ion_auth->errors());
                    redirect('', 'refresh');
                }
            } else {
                $data['errors'] = $this->form->errors;    
            }
        } else {
            // It is the new user form
            echo "New user!";
        }

[code]


Form Generation Library - El Forum - 01-31-2011

[eluser]Mantra of Doom[/eluser]
Hi everyone,

I have a two page form on my site. The first page of the form is the same for everyone and posts to one table called Characters. The second page of the form changes depending on a drop down selection on the first page. Right now, I have the second page split up into different controllers depending on which option is selected, but I'm not sure how to send the user to the correct controller once the first form is submitted. The data in the second page of the form is also save to a different table, again, depending on that one selection.

Can I call an if statement in the onsuccess method? What would be the best practice for this sort of thing? There are 30 options in the list to choose from and there could be more depending on the growth of the site.


Form Generation Library - El Forum - 02-08-2011

[eluser]pabloheim[/eluser]
Hi !

anyone has tested this library on codeigniter 2?


Form Generation Library - El Forum - 02-08-2011

[eluser]Basketcasesoftware[/eluser]
I'm about to try it. It is using PHP 5.0, so there shouldn't be a compatibility problem that way anyways.


Form Generation Library - El Forum - 02-08-2011

[eluser]joytopia[/eluser]
[quote author="pabloheim" date="1297218284"]Hi !

anyone has tested this library on codeigniter 2?[/quote]

Yes, I am using it on codeigniter 2.
No problems.

Best regards
Bernd


Form Generation Library - El Forum - 02-09-2011

[eluser]pabloheim[/eluser]
[quote author="joytopia" date="1297249798"][quote author="pabloheim" date="1297218284"]Hi !

anyone has tested this library on codeigniter 2?[/quote]

Yes, I am using it on codeigniter 2.
No problems.

Best regards
Bernd[/quote]

Great!. im going to test it right now!


Form Generation Library - El Forum - 02-11-2011

[eluser]sahanlak[/eluser]
Just got an error,

Code:
Message:  Object of class El could not be converted to string
Filename: helpers/form_helper.php Line Number: 1003

Quote:->text('method', 'Payment Method', '', $user->method)

Error was gone after this
Code:
->text('payment_method', 'Payment Method', '', $user->method)
i think field name threw the error "method"


Form Generation Library - El Forum - 02-11-2011

[eluser]sahanlak[/eluser]
Code:
->select('payment_method', $methods, 'Payment Method', $user->method)

Generates

Code:
<select name="payment_method[]" id="payment_method">
<option value="">None</option>
<option value="1">Paypal</option>
<option value="2">Moneybookers</option>
</select>

why its adding the [] ?


Form Generation Library - El Forum - 02-11-2011

[eluser]Mat-Moo[/eluser]
http://www.frankmichel.com/formgenlib/user_guide/elements/select.html
Quote "Note: This method will return the selected values as an array."
That's why...


Form Generation Library - El Forum - 02-11-2011

[eluser]sahanlak[/eluser]
[quote author="Mat-Moo" date="1297444418"]http://www.frankmichel.com/formgenlib/user_guide/elements/select.html
Quote "Note: This method will return the selected values as an array."
That's why...[/quote]

Oh ok, I didn't think so since its a single select drop down. Thanks