Creating radio buttons, checkboxes, and select lists is a little tricky in Webform, since they're all part of the "select" component type. To create these types, follow the instructions below for the type of element you are trying to create.
- Select list (single selection) - choose the "Select options" type, enter the values and label, and make sure "Listbox" option is checked (on).
- Select list (multiple selection) - choose the "Select options" type, enter the values and label, then choose the "Multiple" advanced setting, and make sure "Listbox" option is checked (on).
- Checkbox - choose the "Select options" type, enter the value and label, then choose the "Multiple" advanced setting (even if you just want one checkbox to appear), and make sure "Listbox" option is not on.
- Checkboxes (multiple) - choose the "Select options" type, enter the values and label, then choose the "Multiple" advanced setting, and make sure "Listbox" option is not on.
- Radio buttons - choose the "Select options" type, enter the values and label. Make sure both the 'Multiple' advanced setting and "Listbox" option settings are not on.
Options can be grouped for listboxes only ("Listbox" option setting on).
Note if the default option is left blank, an option for "- Please select -" will be added automatically for non-required fields and "- Select an option -" for required field.
Entering options through the interface
For most users, options will be defined through the Webform interface after adding a new "Select options" component. When adding or editing a component, you may specify list options in a textarea. Note that if you install the Option element module, specifying options is much cleaner than the single textarea approach used by default.
Without Options Element module, you'll be given an options box where options are specified as key|value pairs and optionally grouped by using brackets such as <groupname>
. For example a country list:
<Europe>
nl|The Netherlands
be|Belgium
fr|France
<Africa>
tu|Tunisia
sa|South Africa
<Asia>
ru|Russia
cn|China
<>
key|some country that is in no group
Defined options through code
If you have a list of data that is regularly customized through some database value or some other dynamic criteria, you may consider having the options generated by a predefined list. Webform includes a few pre-defined lists by default, such as Days of the Week, US States, and Countries of the world (with either Countries API in Drupal 6 or out-of-box with Drupal 7). You can create your own predefined lists by using the webform_webform_select_options_info
hook. To do this, create an empty module or edit an existing custom module. In yourmodule.module, add a function yourmodule_webform_select_options_info()
. This function must return an array of pre generated select boxes. In order to return the above select box the code would look like this:
/**
* Implements hook_webform_select_options_info().
*/
function yourmodule_webform_select_options_info() {
$items = array();
$items['countries'] = array(
'title' => t('Countries'),
'options callback' => 'webform_options_countries',
);
return $items;
}
/**
* Webform options info callback.
*/
function webform_options_countries() {
$countries = array(
t('Europe') => array (
'nl' => t('The Netherlands'),
'be' => t('Belgium'),
'fr' => t('France'),
),
t('Africa') => array (
'tu' => t('Tunisia'),
'sa' => t('South Africe'),
),
t('Asia') => array (
'ru' => t('Russia'),
'cn' => t('China'),
),
'key' => t('some country that is in no group'),
);
return $countries;
}
Select list extension modules:
- Options Element: Provides a better UI for creating select list options.
- Country codes API: Adds a countries list to the pre-built options lists.
- Select (or other): Allows for a textfield for "Other..." options in select lists and radio buttons.
- View Reference Component: Use a View as the data source for select options instead of hard-coding them.
- Webform Conditional: Makes a field appear or not depending on the value of a previous select option on the same page. Note: This can be done without Webform Conditional, but the dependent field must be on a separate page.
Comments
EULA page
Great! You can create a EULA as the first page using the checkbox option and the "pagebreak" feature (http://drupal.org/node/324779)
Obtain list from taxonomy vocabulary
Just in case anyone wants to get a list from a taoxonomy vocabulary I did this - although it works it might not be the best solution and I am sure someone from the community will point out a better way but here goes:
Bear in mind that the keys in the resulting $vocabulary array are the term ID's although you might not need this, you could just as easily use $vocabulary[] if you purely wanted to present a list to someone and not worry about the term ID's being keys in the resulting select list.
It seems that this is a good
It seems that this is a good method. How about integration with AHAH? For example, if the taxonomy contains a list of countries and cities and we have two fields - country and city, and the city depends on the country.
I don't get it - after adding
I don't get it - after adding this dynamic code to your module, then how do you add the options using the webform UI? There's nothing to choose. Any help?
I'm asking the same thing.
I'm asking the same question. OK. I have created a blank module, and added the necessary code to it.. Now what?
This works well. But how do I
This works well.
But how do I set one of these values as default? In your example, if you wanted to make the option with tid 34 default, how would you do that?
Not working
Just to let you know, the above code is not working for me. Did try with mutiple queries and even after system restart.
Thanks
VirtueReview.com
Change select list prompt from 'none'
By default, select lists read 'none' unless you assign a default.
Is there a way to change the value to something besides 'none' without setting a default? Grouping sounded promising but it doesn't help.
Token value from profile
I'm having problem to get token value from core profile to webform. I have some checkboxes and another field with radio buttons in core profile module and I want to populate their values in webform as default values with the help of token module but it does not appear to be working.
Please help
Thanks
Changing '- None - '
Just so you know:
make the first option
0| - Select -
or whatever and then put the0
in the 'Default value' box.But this isn't going to work for mandatory fields unless you put in some additional validation.
http://modelagnostic.co.uk/
Image option
Hi,
I'm looking for a solution to add images as option values. Just like Yes/No, I want Image1/Image2.
Can you someone please help me with this?
Thanks
Alice
Custom name field
Hi,
I have created a text field and I want the name attribute to be "subscriber_firstname", however the module is wrapping this with a submitted[] like so submitted[subscriber_firstname]. Is there a way to remove the submitted[] around my custom name field ?
cheers,
Forget about checkbox in Drupal 7
Because of the radios bug in Drupal 7 http://drupal.org/node/811542, you want to avoid using radios as much as possible! Unfortunately you cannot create a single valued set of checkboxes.
0|No
1|Yes
If you set allowed values = 1, then you are FORCED to use a radio. If you select UNLIMITED, then your users can check both of those options. In other words, you are SOL with Drupal 7 and radios. They are fixing this in Drupal 8
Weirdness with Options Elements as well as token question.
I have the basic Webform module: Webform 6.x-3.11. I am trying to add a form with a simple drop menu that should pass a value as a token to the output URL.
The option list for the field with the field key [fleet] is:
bocasmall| 1-4
rmi_large| 5-100
The custom url is set to: %value[fleet] With a redirect set for bocasmall to go elsewhere....
The option list keeps relaying the value 1-4 or 5-100 for the value pairs, instead of the bocasmall/rmi_large value, which is what I would read the docs to say should be passed. ( The result page keeps passing the value 1 4 to the search engine....not what I want)
Also the docs seems to disagree on where the custom URL should read %get[fleet] or %value[fleet] I have tried both but niether work.....
Any suggestions would be welcome.
Adding an option requirement
I am confused as to how to add mandatory fields to a webform contingent on another field.
For example:
Are you bringing children?*MANDATORY*
1| Yes
2| No
If option 1 is selected, I would like the following questions mandatory
Child's Name
Child's Birthdate
Child's Gender
If option 2 is selected, then the above fields should not be made mandatory.
Any advice?
Conditional Fields module
Check out the Conditional Fields module. It will allow you to make things visible/invisible based on choices. It might not work exactly like you want it, but you can always rephrase and restructure your questions and flow to make it just right with the conditional fields module.
For example:
If "Yes", then show questions about children
If "No", then hide questions about children
http://drupal.org/project/conditional_fields
Check All / Uncheck All
I'm surprised I haven't seen this anywhere; but what about "Check All" and "Uncheck All" options?
Worth developing
Need an All option followed by individual selections. Default to All. If an individual item is selected, the All option is switched off.
[*] All
[ ] A
[ ] B
[ ] C
jQuery could do this. If anything other than All is selected, All is switched off. Based on conventions, jQuery could find elements with a specific class then perform the changes.
Look for div.form-checkboxes
Look inside for input.checkbox value = all
Set jQuery to react on input change within the div.
petermoulding.com/web_architect
1.how to add checkbox in webform
1.Select the select options form field
2.Type in options in the format key|value
3.Check multiple
4. Check Randomize options
Mandatory checkbox list
how can I make a list of checkboxes where every item on the list is mandatory. Basically I have a registration page where the user needs to select a list checkboxes (all mandatory) before proceeding to the next field.
Fetching Option Group value for Selected Drop-down value
I have a requirement for Webform (D7) where i have a selection option in which i have two option groups and multiple options under those groups. I want to send a Email , subject of which has to include the Option Group and Option.
Eg -
"< Europe >"
be|Belgium
fr|France
"< Africa >"
tu|Tunisia
sa|South Africa
I want to send a Email subject as "Europe: Belgium"
Is there any token / way to directly access the Option Group value for the selected option?
nice, but am too looking for
nice, but am too looking for solution to this.
DarylOrtiz
Creating Checkboxes, Radio Buttons, or Select Lists
//In initialization code:
ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
ImageIcon rightButtonIcon = createImageIcon("images/left.gif");
b1 = new JButton("Disable middle button", leftButtonIcon);
b1.setVerticalTextPosition(AbstractButton.CENTER);
b1.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
b1.setMnemonic(KeyEvent.VK_D);
b1.setActionCommand("disable");
b2 = new JButton("Middle button", middleButtonIcon);
b2.setVerticalTextPosition(AbstractButton.BOTTOM);
b2.setHorizontalTextPosition(AbstractButton.CENTER);
b2.setMnemonic(KeyEvent.VK_M);
b3 = new JButton("Enable middle button", rightButtonIcon);
//Use the default text position of CENTER, TRAILING (RIGHT).
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enable");
b3.setEnabled(false);
//Listen for actions on buttons 1 and 3.
b1.addActionListener(this);
b3.addActionListener(this);
b1.setToolTipText("Click this button to disable "
+ "the middle button.");
b2.setToolTipText("This middle button does nothing "
+ "when you click it.");
b3.setToolTipText("Click this button to enable the "
+ "middle button.");
...
}
public void actionPerformed(ActionEvent e) {
if ("disable".equals(e.getActionCommand())) {
b2.setEnabled(false);
b1.setEnabled(false);
b3.setEnabled(true);
} else {
b2.setEnabled(true);
b1.setEnabled(true);
b3.setEnabled(false);
}
}
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = ButtonDemo.class.getResource(path);
...//error handling omitted for clarity...
return new ImageIcon(imgURL);
thanks
http://www.bankersadda.net
Not Worked
when i tried to paste this code, it didn't worked. Here we have put many things including your code, and the specific part of it;
b3 = new JButton("Enable middle button", rightButtonIcon);
//Use the default text position of CENTER, TRAILING (RIGHT).
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enable");
b3.setEnabled(false);
Shows big error, I guess the command should be changed to make it more relevant.
Thanks
Bestreviewsage.com