Radio buttons and pulldown selects from a list field

6 posts by 2 authors in: Forums > CMS Builder
Last Post: June 27, 2012   (RSS)

Re: [aev] Radio buttons and pulldown selects from a list field

By Jason - June 26, 2012

Hi,

No problem. You can get the list options by using the getListOptions() function. You can then output this information as either radio buttons or as a drop down, depending on what you want. Here are some basic examples:

EXAMPLE:
//radio buttons
<?php foreach (getListOptions('mySection', 'myListField') as $value => $label): ?>
<input type = "radio" name = "myListField" value = "<?php echo $value;?>" /><?php echo $label;?> <br/>
<?php endforeach ?>

//select drop down
<select name = "myListField">
<?php foreach (getListOptions('mySection', 'myListField') as $value => $label): ?>
<option value = "<?php echo $value;?>"><?php echo $label;?></option>
<?php endforeach ?>
</select>


Note you'll need to change values to match what is in your database

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Radio buttons and pulldown selects from a list field

By aev - June 27, 2012

Hi,

thanks for the help so far, the problem is that I'm getting an error using the code you provided:

Notice: Undefined index: produkt in /var/www/vhosts/vike.no/httpdocs/cmsAdmin/lib/database_functions.php on line 451 Unknown optionsType ''!

I replaced mySection with the sectionname I'm using and myListField with a field called 'produkt' inside that section. Like this:

//radio buttons
<?php foreach (getListOptions('contactformRecord', 'produkt') as $value => $label): ?>
<input type="radio" name="myListField" value="<?php echo $value;?>" /><?php echo $label;?> <br/>
<?php endforeach ?>


Any suggestions?

-aev-

Re: [aev] Radio buttons and pulldown selects from a list field

By Jason - June 27, 2012

Hi,

The error coming back is "Unknown optionsType". Is "produkt" set up as a list field? If so, what type? Could you attach a screen shot of your field set up?

Also, you'll want to change the name of your radio button to "produkt" to make it easier to work with.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Radio buttons and pulldown selects from a list field

By aev - June 27, 2012


Yes it is set up as a list field. See attached screenshot.


-aev-
Attachments:

produkt.png 79K

Re: [aev] Radio buttons and pulldown selects from a list field

By Jason - June 27, 2012

Hi,

I took a look at your screenshot. I think the issue here is that you're not using your section name in the function call. From the screen shot, it looks like your section is called "foresporsler_web".

If this is the case, try this:

//radio buttons
<?php foreach (getListOptions('foresporsler_web', 'produkt') as $value => $label): ?>
<input type="radio" name="produkt" value="<?php echo $value;?>" /><?php echo $label;?> <br/>
<?php endforeach ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/