Radio buttons and pulldown selects from a list field
6 posts by 2 authors in: Forums > CMS Builder
Last Post: June 27, 2012 (RSS)
By aev - June 26, 2012
in CMSB we can create a field type called "list", and pre-populate it with values (list options) either manually or from db/mysql queries and decide how it should appear/behave using the "Display As" settings.
Does anyone know the code for using this field in the final web page (viewer page)?
To clarify: We want to make active radio buttons or a pulldown select from the values in the "list-field". This will then be used to send values back to CMSB using a form. I don't need the form/mysql code, just the radio buttons and pulldown code.
-aev-
Re: [aev] Radio buttons and pulldown selects from a list field
By Jason - June 26, 2012
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
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
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-
Re: [aev] Radio buttons and pulldown selects from a list field
By Jason - June 27, 2012
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/