Forums / Developer / Radio buttons within forms

Radio buttons within forms

Author Message

Paul Forsyth

Wednesday 16 April 2003 12:07:17 am

Im having difficult using radio buttons from within forms and mapping them to attributes.

I have a form that will email comments and information from a user to me. Standard information collector stuff. Most of the form elements I am rendering using code such as:

{attribute_edit_gui attribute=$node.data_map.message}

The trouble comes when using radio buttons. There isnt a
datatype for radio buttons - the closest seems to be either checkbox or enum... so using a function like attribute_edit_gui isnt possible.

A workaround was to create an attribute, find the value in the database corresponding to that attribute and put this into the name value for the list of radio buttons, eg:

<input type="radio" name="ContentObjectAttribute_ezstring_data_text_908" value="Accounts">Accounts

<input type="radio" name="ContentObjectAttribute_ezstring_data_text_908" value="Sales">Sales

But there must be an easier way to do this. What is the best way to handle radio buttons from within forms?

Thanks

Paul

Jan Borsodi

Wednesday 16 April 2003 1:29:15 am

Had you used enum you would been able to get radiobuttons by choosing it in the class edit.

Using other datatypes (int,string) requires some custom template code. If you know the identifier of the attribute you can access it directly and generate the radioboxes.

Example:
{let myattribute=$node.data_map.myidentifier}
{section name=Radio loop=array('Accounts','Sales')}
<input type="radio" name="ContentObjectAttribute_ezstring_data_text_{$myattribute.id}" value="{$:item}">{$:item}</input>
{/section}
{/let}

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

Paul Forsyth

Wednesday 16 April 2003 1:51:47 am

Thanks Jan,

I tried out both methods.

I didn't realise that by selecting the enum to be a checkbox i would get radio buttons... Maybe the text needs modified as there is a checkbox datatype.

When i tried attribute_edit_gui the design format it displays wasnt to my liking so I used your second method as ive kept the attribute as a non-enum. Using a enum and going into it to pull out elements for my own design would have been messier code. but each to their own. Im still getting used to form building within ez3 :)

Thanks again, Jan.

Paul