3 require_once 'CRM/Core/Form.php';
6 * Form controller class
8 * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
10 class CRM_Wci_Form_CreateWidget
extends CRM_Core_Form
{
11 function buildQuickForm() {
15 'select', // field type
16 'favorite_color', // field name
17 'Favorite Color', // field label
18 $this->getColorOptions(), // list of options
21 $this->addButtons(array(
24 'name' => ts('Submit'),
29 // export form elements
30 $this->assign('elementNames', $this->getRenderableElementNames());
31 parent
::buildQuickForm();
34 function postProcess() {
35 $values = $this->exportValues();
36 $options = $this->getColorOptions();
37 CRM_Core_Session
::setStatus(ts('You picked color "%1"', array(
38 1 => $options[$values['favorite_color']]
40 parent
::postProcess();
43 function getColorOptions() {
45 '' => ts('- select -'),
47 '#0f0' => ts('Green'),
49 '#f0f' => ts('Purple'),
51 foreach (array('1','2','3','4','5','6','7','8','9','a','b','c','d','e') as $f) {
52 $options["#{$f}{$f}{$f}"] = ts('Grey (%1)', array(1 => $f));
58 * Get the fields/elements defined in this form.
60 * @return array (string)
62 function getRenderableElementNames() {
63 // The _elements list includes some items which should not be
64 // auto-rendered in the loop -- such as "qfKey" and "buttons". These
65 // items don't have labels. We'll identify renderable by filtering on
67 $elementNames = array();
68 foreach ($this->_elements
as $element) {
69 $label = $element->getLabel();
71 $elementNames[] = $element->getName();