2009/10/15 mohanprasad <mo...@thebizmo.com>: > > Hi, > > I am trying to insert a new element in my catalyst controller action using > below code. > i have two hidden fileds, one text box, i am trying to insert the new > element before hidden fields. > > my $form = $self->form; > my $file = "restricted/add/product"; > $form->load_config_filestem($file); > $form->process; > $c->stash->{form} = $form; > my $new_element = $form->element( { type => 'Block', tag => 'label', content > => 'file upload error' } ); > my $pos = $form->get_element({ type => 'Hidden', name => 'media_id'}); > my $hidden_fields = $form->hidden_fields; > $c->log->debug("hidden fields = $hidden_fields"); > $form->insert_before($new_element, $pos);
Hi, Because all the fields are attached to a Fieldset - not directly to the form, you'll find $pos is undef. Because of this, you also need to call insert_before() on the fieldset, not the form. Also, you'll find that if you're creating $new_element on the same form, you'll end up with 2 copies of it after insert_before(), so you should probably be using another form object to create it. You need to do something like this: my $fieldset = $form->get_element; my $pos = $fieldset->get_element( 'media_id' ); my $new_element = $different_form_object->element( \%args ); $fieldset->insert_before( $new_element, $pos ); Cheers, Carl _______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu