[html-formfu] insert a field to defined postion?
Carl Franks
fireartist at gmail.com
Tue Sep 25 15:51:21 GMT 2007
On 25/09/2007, Josef Chladek <josef.chladek at gmail.com> wrote:
> hello again,
>
> I use my .yml for existing users to edit their data, except that the
> can't change the username, so I do not include that in my config.
> if I now want to use the same config for new users to create, I would
> need the field username, I can append it to the bottom of the form,
> but how would I insert it at the beginning of the form? is there a way?
The way I've dealt with this is by having multiple yaml files.
So, if the rest of the fields are in 'user_edit.yml'.
Put the username field in 'user_username.yml'.
Then create a 'user_existing.yml' that looks something like this:
---
load_config_file:
- user_username.yml
- user_edit.yml
Then depending on your need, create your form from either
'user_edit.yml' or 'user_existing.yml'.
A completely different alternative is to use insert_before().
This requires you to use auto_fieldset(), or just manually place the
fields in a fieldset.
Say the first field in the normal form is 'email', then you could do
something like this:
$fieldset = $form->get_element({ type => 'Fieldset' });
$fieldset->insert_before(
HTML::FormFu->new->element({ name => 'username' }),
$form->get_field('email')
);
But that's pretty nasty, and you'd probably be better of with the
first solution :)
Carl
More information about the HTML-FormFu
mailing list