This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » Radio buttons within forms
expandshrink

Radio buttons within forms

Radio buttons within forms

Wednesday 16 April 2003 9:07:17 am - 2 replies

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

Wednesday 16 April 2003 10: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}

Wednesday 16 April 2003 10: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 happy.gif Emoticon

Thanks again, Jan.

Paul

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from