#29521 - Updated extension key name and install and uninstall mysql script file.
[com.zyxware.civiwci.git] / CRM / Wci / Form / CreateWidget.php
CommitLineData
60488185
M
1<?php
2
3require_once 'CRM/Core/Form.php';
4
5/**
6 * Form controller class
7 *
8 * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
9 */
10class CRM_Wci_Form_CreateWidget extends CRM_Core_Form {
11 function buildQuickForm() {
12
13 // add form elements
14 $this->add(
15 'select', // field type
16 'favorite_color', // field name
17 'Favorite Color', // field label
18 $this->getColorOptions(), // list of options
19 true // is required
20 );
21 $this->addButtons(array(
22 array(
23 'type' => 'submit',
24 'name' => ts('Submit'),
25 'isDefault' => TRUE,
26 ),
27 ));
28
29 // export form elements
30 $this->assign('elementNames', $this->getRenderableElementNames());
31 parent::buildQuickForm();
32 }
33
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']]
39 )));
40 parent::postProcess();
41 }
42
43 function getColorOptions() {
44 $options = array(
45 '' => ts('- select -'),
46 '#f00' => ts('Red'),
47 '#0f0' => ts('Green'),
48 '#00f' => ts('Blue'),
49 '#f0f' => ts('Purple'),
50 );
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));
53 }
54 return $options;
55 }
56
57 /**
58 * Get the fields/elements defined in this form.
59 *
60 * @return array (string)
61 */
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
66 // the 'label'.
67 $elementNames = array();
68 foreach ($this->_elements as $element) {
69 $label = $element->getLabel();
70 if (!empty($label)) {
71 $elementNames[] = $element->getName();
72 }
73 }
74 return $elementNames;
75 }
76}