logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: [FormBuilder] Position of radio buttons: msg#00021

Subject: Re: [FormBuilder] Position of radio buttons
This is something I've often wanted to do. I have attacked it two 
different ways, and if anyone has a better suggestion, I'd be happy to 
hear it.

The first approach is to simply build the appropriate <input> tags 
within the template, passing the appropriate field information through 
in a <tmlp_loop> variable. Something like:

<table>
  <tr><th>
  <tmpl_loop options><tr><th><tmpl_var Proj_name></th>
    <td><input type="submit" name="PD<tmpl_var Proj_ID>" 
value="Production"></td></tr>
  </tmpl_loop>
</table>

This is pretty straightforward for submit buttons.

For radio buttons and checkboxes, this approach takes a lot of work and 
seriously reduces the benefits of using FormBuilder, since you have to 
dig out the state of each option. Another approach is to dig out the 
actual field object:

  @fields = $form->field;
  %fields = map { ( $_->{name} => $_ ) } @fields;
  $myfield = $fields{myfieldname};

and then use the field's 'tag' method to get all the option code:

  $html = $myfield->tag;

and split it up by line to get the individual options:

  @options = map [ name => $_ ], split( /\n/, $html );

and pass them on to HTML::Template:

  $form->tmpl_param( options => \@options )

Then you can use <tmpl_loop options> to loop through the options.

As you may have noticed, this approach uses some not-entirely-documented 
features. For starters, @fields = $form->field; is documented to return 
an array of field names, but in fact returns an array of field objects. 
The names are produced magically via 'stringification' if you try to 
print the objects. Then the fact that there is a 'name' field within the 
object to identify which field it refers to is also internal to the 
module. Finally, the fact that the options are separated by newlines in 
the html rendering is not documented, so could be subject to change.

Ideally, there would be a documented method to get at the field object 
by name, and the 'tag' method would return an array of options on 
want_array.

-Norton Allen

kreso kreso wrote:

> Hello!
> I have a problem. I defined field with radio buttons:
> $form->field(name =>'odabir',
>       options=>['url','text','file'],
>       value => 'text');
> and i`m using html::template. So how can i place that three radio 
> buttons on position that i want? They are all placed on this 
> place<tmp_var field-odabir>. Can it be done to place each button lets 
> say like this:
> @ first button
> ............................
> ............................
> @ second button
> ...........................
> ..........................
> @ third button
> Thanks!
>
> ------------------------------------------------------------------------
> Check out the all-new Yahoo! Mail beta 
> <http://us.rd.yahoo.com/evt=43257/*http://advision.webevents.yahoo.com/mailbeta>
>  
> - Fire up a more powerful email and get things done faster.
>
>------------------------------------------------------------------------
>
>_______________________________________________
>FBusers mailing list
>FBusers@xxxxxxxxxxxxxxx
>http://www.formbuilder.org/mailman/listinfo/fbusers
>

_______________________________________________
FBusers mailing list
FBusers@xxxxxxxxxxxxxxx
http://www.formbuilder.org/mailman/listinfo/fbusers



<Prev in Thread] Current Thread [Next in Thread>