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 - 02-14-2011

[eluser]JonoB[/eluser]
Just to make sure that I am not missing something obvious here.

When initially showing a form, all the values are blank. User then posts, but form fails validation. However, we want to reshow all the inputs that the user posted.

Code:
->text('first_name', 'First Name', 'trim|required', $user['first_name'])

When initially showing the form $user['first_name'] will be null, so there will not be a default value.

This means that every time there is a failed post, the entire form has to be re-generated using the library.

Is this correct? And, if it is, does it add much to the processing overhead?

(PS - I'm brand new to MVC and CI, loving it. Including this library)


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

[eluser]c-s-n[/eluser]
Hi JonoB,

yes, the library generates the form again on each page load. For the action attribute I mostly use the same class method in which I construct the form.
The form is always constructed, as it will then evaluate all sent POST data and generate the error classes/strings. And as long as there is POST data for the given form element name, your default value seems to be overridden.

For checking, if the form was successfully checked, I use
Code:
if($this->form->valid)
In that block I do some things with the sent data and redirect back to another page...


But anyway Wink Why I just came to this thread:

I think I have found a not documented (or not seen) limitation to all the name|id parameters:
If I use the word 'validated' (here as a checkbox), the whole validation process gets broken! That means, no shown errors etc. and the above mentioned $this->form->valid is true even on every error produced one can imagine...
Took me a bit time to find out O.o

Hhhm... maybe one can fix/workaround this one time? And why is it happening? Has it to do with the class attribute "validated"?

Best regards


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

[eluser]Unknown[/eluser]
Hi and thanks for your great lib,

Just a question how does postprocess work ?
I've seen a another message it is the same as in MidgetForms but I can't find the doc (http://avanthill.com/mfmanual is dead).
Have you found out how it is used ?

And what are the "rules" in _do_onsuccess_matches() ( There are probably related to postprocess).

Finally I think I've spotted a bug in _do_onsuccess(), call_user_func_array requires $func['values'] to be an array.
So I've added a line in the else block just above :
Code:
else
{
  // old: $this->_do_onsuccess_matches($val, $func['values'], $func['rules']);
  $this->_do_onsuccess_matches('', $func['values'], $func['rules']);
  $func['values'] = array($func['values']); // That's the line I've added
}
call_user_func_array($func['function'], $func['values']);
Thanks.


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

[eluser]macigniter[/eluser]
[quote author="c-s-n" date="1298069136"]
I think I have found a not documented (or not seen) limitation to all the name|id parameters:
If I use the word 'validated' (here as a checkbox), the whole validation process gets broken! That means, no shown errors etc. and the above mentioned $this->form->valid is true even on every error produced one can imagine...
Took me a bit time to find out O.o

Hhhm... maybe one can fix/workaround this one time? And why is it happening? Has it to do with the class attribute "validated"?
[/quote]

This is the same problem sahanlak had in this thread. You are absolutely right, it has to do with the class attributes. Both "validated" and "method" are class variables and therefore cannot be used as names for form elements. This includes the following 'reserved words':

Code:
ci
config
lang
fieldsets
indented
columns
action
method
multipart
atts
error
errors
error_string
error_array
error_open
error_close
model
valid
validated
captcha
recaptcha
recaptcha_error
retrieved

I am just working on some updates on the library and will be releasing an update very soon. It will include some bugfixes and a new feature to supply attributes to both the element itself and its label separately. Stay tuned!


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

[eluser]macigniter[/eluser]
[quote author="polobricolo" date="1298075170"]Hi and thanks for your great lib,
Just a question how does postprocess work ?

And what are the "rules" in _do_onsuccess_matches() ( There are probably related to postprocess).
[/quote]

These methods are a relict of MidgetForms and I haven't looked into them in a long time.

It's nice to use onsuccess() if you have a simple function to call like in this example.

But to be honest I haven't used it at all, ever.

It'd be great to hear it from FGL users... does anyone use the onsuccess() or postprocess() methods? If yes, how? Let us know and maybe we can learn from your best practices!


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

[eluser]Mantra of Doom[/eluser]
Macigniter,

I use onsuccess to do a redirect like in the example in the documentation.

I, too, was wondering if this was used for anything else other than redirects.


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

[eluser]macigniter[/eluser]
@mantra of Doom: Did you figure out the onchange issue? That must have been related to camelCase. You should use "onchange", not "onChange".


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

[eluser]JonoB[/eluser]
Apologies if this is a silly question: is it possible to get checkbox labels aligned on the left of the checkbox?


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

[eluser]Maglok[/eluser]
@macigniter: Do you perhaps have an idea how to handle two forms? I posted it on the previous page, but it was the last post and must have gotten overlooked.


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

[eluser]macigniter[/eluser]
[quote author="Maglok" date="1298468821"]@macigniter: Do you perhaps have an idea how to handle two forms? I posted it on the previous page, but it was the last post and must have gotten overlooked.[/quote]

Hi there, simply do all the validation for form #1 before calling the clear() method. And then do the same thing after the code for form #2.

Code:
// form #1
$this->form->...

$this->form->validate();

if ($this->form->valid)
{
    // do stuff if form #1 is valid
}

$this->form->clear();

// form #2
$this->form->...

$this->form->validate();

if ($this->form->valid)
{
    // do stuff if form #2 is valid
}

That should work. Let me know if it doesn't!