API
2 years ago
Access
2 years ago
Application
2 years ago
Archive
2 years ago
ArchiveProcessor
2 years ago
Archiver
2 years ago
AssetManager
2 years ago
Auth
2 years ago
Category
2 years ago
Changes
2 years ago
CliMulti
2 years ago
Columns
2 years ago
Concurrency
2 years ago
Config
2 years ago
Container
2 years ago
CronArchive
2 years ago
DataAccess
2 years ago
DataFiles
2 years ago
DataTable
2 years ago
Db
2 years ago
DeviceDetector
2 years ago
Email
2 years ago
Exception
2 years ago
Http
2 years ago
Intl
2 years ago
Log
2 years ago
Mail
2 years ago
Measurable
2 years ago
Menu
2 years ago
Metrics
2 years ago
Notification
2 years ago
Period
2 years ago
Plugin
2 years ago
ProfessionalServices
2 years ago
Report
2 years ago
ReportRenderer
2 years ago
Scheduler
2 years ago
Segment
2 years ago
Session
2 years ago
Settings
2 years ago
Tracker
2 years ago
Translation
2 years ago
Twig
2 years ago
UpdateCheck
2 years ago
Updater
2 years ago
Updates
2 years ago
Validators
2 years ago
View
2 years ago
ViewDataTable
2 years ago
Visualization
2 years ago
Widget
2 years ago
.htaccess
2 years ago
Access.php
2 years ago
Archive.php
2 years ago
ArchiveProcessor.php
2 years ago
AssetManager.php
2 years ago
Auth.php
2 years ago
AuthResult.php
2 years ago
BaseFactory.php
2 years ago
Cache.php
2 years ago
CacheId.php
2 years ago
CliMulti.php
2 years ago
Common.php
2 years ago
Config.php
2 years ago
Console.php
2 years ago
Context.php
2 years ago
Cookie.php
2 years ago
CronArchive.php
2 years ago
DI.php
2 years ago
DataArray.php
2 years ago
DataTable.php
2 years ago
Date.php
2 years ago
Db.php
2 years ago
DbHelper.php
2 years ago
Development.php
2 years ago
ErrorHandler.php
2 years ago
EventDispatcher.php
2 years ago
ExceptionHandler.php
2 years ago
FileIntegrity.php
2 years ago
Filechecks.php
2 years ago
Filesystem.php
2 years ago
FrontController.php
2 years ago
Http.php
2 years ago
IP.php
2 years ago
Log.php
2 years ago
LogDeleter.php
2 years ago
Mail.php
2 years ago
Metrics.php
2 years ago
NoAccessException.php
2 years ago
Nonce.php
2 years ago
Notification.php
2 years ago
NumberFormatter.php
2 years ago
Option.php
2 years ago
Period.php
2 years ago
Piwik.php
2 years ago
Plugin.php
2 years ago
Profiler.php
2 years ago
ProxyHeaders.php
2 years ago
ProxyHttp.php
2 years ago
QuickForm2.php
2 years ago
RankingQuery.php
2 years ago
ReportRenderer.php
2 years ago
Request.php
2 years ago
Segment.php
2 years ago
Sequence.php
2 years ago
Session.php
2 years ago
SettingsPiwik.php
2 years ago
SettingsServer.php
2 years ago
Singleton.php
2 years ago
Site.php
2 years ago
SiteContentDetector.php
2 years ago
SupportedBrowser.php
2 years ago
TCPDF.php
2 years ago
Theme.php
2 years ago
Timer.php
2 years ago
Tracker.php
2 years ago
Twig.php
2 years ago
Unzip.php
2 years ago
UpdateCheck.php
2 years ago
Updater.php
2 years ago
UpdaterErrorException.php
2 years ago
Updates.php
2 years ago
Url.php
2 years ago
UrlHelper.php
2 years ago
Version.php
2 years ago
View.php
2 years ago
bootstrap.php
2 years ago
dispatch.php
2 years ago
testMinimumPhpVersion.php
2 years ago
QuickForm2.php
127 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | * |
| 9 | */ |
| 10 | namespace Piwik; |
| 11 | |
| 12 | use HTML_QuickForm2; |
| 13 | use HTML_QuickForm2_InvalidArgumentException; |
| 14 | use HTML_QuickForm2_Node; |
| 15 | use HTML_QuickForm2_NotFoundException; |
| 16 | use HTML_QuickForm2_Renderer; |
| 17 | /** |
| 18 | * Manages forms displayed in Twig |
| 19 | * |
| 20 | * For an example, @see Piwik\Plugins\Login\FormLogin |
| 21 | * |
| 22 | * @see HTML_QuickForm2, libs/HTML/QuickForm2.php |
| 23 | * @link http://pear.php.net/package/HTML_QuickForm2/ |
| 24 | */ |
| 25 | abstract class QuickForm2 extends HTML_QuickForm2 |
| 26 | { |
| 27 | protected $a_formElements = array(); |
| 28 | public function __construct($id, $method = 'post', $attributes = null, $trackSubmit = false) |
| 29 | { |
| 30 | if (!isset($attributes['action'])) { |
| 31 | $attributes['action'] = \Piwik\Url::getCurrentQueryString(); |
| 32 | } |
| 33 | if (!isset($attributes['name'])) { |
| 34 | $attributes['name'] = $id; |
| 35 | } |
| 36 | parent::__construct($id, $method, $attributes, $trackSubmit); |
| 37 | $this->init(); |
| 38 | } |
| 39 | /** |
| 40 | * Class specific initialization |
| 41 | */ |
| 42 | public abstract function init(); |
| 43 | /** |
| 44 | * The elements in this form |
| 45 | * |
| 46 | * @return array Element names |
| 47 | */ |
| 48 | public function getElementList() |
| 49 | { |
| 50 | return $this->a_formElements; |
| 51 | } |
| 52 | /** |
| 53 | * Wrapper around HTML_QuickForm2_Container's addElement() |
| 54 | * |
| 55 | * @param string|HTML_QuickForm2_Node $elementOrType Either type name (treated |
| 56 | * case-insensitively) or an element instance |
| 57 | * @param mixed $name Element name |
| 58 | * @param mixed $attributes Element attributes |
| 59 | * @param array $data Element-specific data |
| 60 | * @return HTML_QuickForm2_Node Added element |
| 61 | * @throws HTML_QuickForm2_InvalidArgumentException |
| 62 | * @throws HTML_QuickForm2_NotFoundException |
| 63 | */ |
| 64 | public function addElement($elementOrType, $name = null, $attributes = null, array $data = array()) |
| 65 | { |
| 66 | if ($name != 'submit') { |
| 67 | $this->a_formElements[] = $name; |
| 68 | } |
| 69 | return parent::addElement($elementOrType, $name, $attributes, $data); |
| 70 | } |
| 71 | public function setChecked($nameElement) |
| 72 | { |
| 73 | foreach ($this->_elements as $key => $value) { |
| 74 | if ($value->_attributes['name'] == $nameElement) { |
| 75 | $this->_elements[$key]->_attributes['checked'] = 'checked'; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | public function setSelected($nameElement, $value) |
| 80 | { |
| 81 | foreach ($this->_elements as $key => $value) { |
| 82 | if ($value->_attributes['name'] == $nameElement) { |
| 83 | $this->_elements[$key]->_attributes['selected'] = 'selected'; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | /** |
| 88 | * Ported from HTML_QuickForm to minimize changes to Controllers |
| 89 | * |
| 90 | * @param string $elementName |
| 91 | * @return mixed |
| 92 | */ |
| 93 | public function getSubmitValue($elementName) |
| 94 | { |
| 95 | $value = $this->getValue(); |
| 96 | return isset($value[$elementName]) ? $value[$elementName] : null; |
| 97 | } |
| 98 | public function getErrorMessages() |
| 99 | { |
| 100 | $messages = array(); |
| 101 | foreach ($this as $element) { |
| 102 | $messages[] = $element->getError(); |
| 103 | } |
| 104 | return array_filter($messages); |
| 105 | } |
| 106 | protected static $registered = false; |
| 107 | /** |
| 108 | * Returns the rendered form as an array. |
| 109 | * |
| 110 | * @param bool $groupErrors Whether to group errors together or not. |
| 111 | * @return array |
| 112 | */ |
| 113 | public function getFormData($groupErrors = true) |
| 114 | { |
| 115 | if (!self::$registered) { |
| 116 | HTML_QuickForm2_Renderer::register('smarty', 'HTML_QuickForm2_Renderer_Smarty'); |
| 117 | self::$registered = true; |
| 118 | } |
| 119 | // Create the renderer object |
| 120 | $renderer = HTML_QuickForm2_Renderer::factory('smarty'); |
| 121 | $renderer->setOption('group_errors', $groupErrors); |
| 122 | // build the HTML for the form |
| 123 | $this->render($renderer); |
| 124 | return $renderer->toArray(); |
| 125 | } |
| 126 | } |
| 127 |