/** * Sets the form to the view * @param zibo\library\html\form\Form $form Form of the data * @return null */ protected function setForm(Form $form) { $fields = array(); $hiddenFields = array(); $fieldIterator = $form->getFields()->getIterator(); foreach ($fieldIterator as $fieldName => $field) { if ($field instanceof SubmitField) { continue; } if (!$field instanceof HiddenField) { $fields[$fieldName] = $fieldName; continue; } if ($fieldName == Form::SUBMIT_NAME . $form->getName()) { continue; } $hiddenFields[$fieldName] = $fieldName; } if ($form instanceof ScaffoldForm) { $fieldLabels = $form->getFieldLabels(); } else { $fieldLabels = array(); } $this->set('form', $form); $this->set('fields', $fields); $this->set('hiddenFields', $hiddenFields); $this->set('fieldLabels', $fieldLabels); }
/** * Gets the data object from the provided form * @param zibo\library\html\form\Form $form * @return mixed Data object */ protected function getFormData(Form $form) { $data = $form->getData(); if (!$data->id) { $data->locale = LocalizeController::getLocale(); } return $data; }
/** * Performs validation of the provided form. * @param Form $form The form to validate * @return null */ public function isValid(Form $form) { $username = $form->getUsername(); $email = $form->getEmail(); if (!$username && !$email) { $error = new ValidationError(self::TRANSLATION_ERROR_NO_INPUT, 'Please provide a username or a password'); $validationException = $form->getValidationException(); $validationException->addErrors(ResetPasswordForm::FIELD_USERNAME, array($error)); } }
/** * Performs validation of the provided form. * @param Form $form The form to validate * @return null */ public function isValid(Form $form) { $password = $form->getPassword(); $passwordConfirm = $form->getPasswordConfirmation(); if ($password && $passwordConfirm && $password != $passwordConfirm) { $error = new ValidationError(self::TRANSLATION_ERROR_PASSWORD_MATCH, 'The provided passwords do not match'); $validationException = $form->getValidationException(); $validationException->addErrors(NewPasswordForm::FIELD_PASSWORD, array($error)); } }
/** * Adds the necessairy fields to the form of this table * @return null */ protected function prepareForm() { $factory = FieldFactory::getInstance(); if ($this->hasActions()) { $options = $this->getOptionsFromKeys($this->actions); $translator = I18n::getInstance()->getTranslator(); array_unshift($options, $translator->translate(self::TRANSLATION_ACTIONS)); $actionField = $this->createListField($factory, $options, self::FIELD_ACTION); $idField = $factory->createField(FieldFactory::TYPE_OPTION, self::FIELD_ID); $idField->setIsMultiple(true); $idField->setOptions($this->values); $this->form->addField($actionField); $this->form->addField($idField); } if ($this->hasSearch()) { $searchQueryField = $factory->createField(FieldFactory::TYPE_STRING, self::FIELD_SEARCH_QUERY, $this->searchQuery); $this->form->addField($searchQueryField); } if ($this->hasOrderMethods()) { $options = $this->getOptionsFromKeys($this->orderMethods); $orderField = $this->createListField($factory, $options, self::FIELD_ORDER_METHOD, $this->orderMethod); $this->form->addField($orderField); } if ($this->paginationOptions) { $pageItemsField = $this->createListField($factory, $this->paginationOptions, self::FIELD_PAGE_ROWS, $this->pageRows); $this->form->addField($pageItemsField); } }
/** * Construct a new form * @param string $action action where this form will point to * @return null */ public function __construct($action) { parent::__construct($action, self::NAME); $factory = FieldFactory::getInstance(); $this->addField($factory->createField(FieldFactory::TYPE_TEXT, self::FIELD_COMMENT)); $this->addField($factory->createSubmitField(self::FIELD_SUBMIT, self::TRANSLATION_SUBMIT)); }
/** * Construct this form * @param string $action url where this form will point to * @param string $query optional search query to preset the form * @return null */ public function __construct($action, $query = null) { parent::__construct($action, self::NAME); $factory = FieldFactory::getInstance(); $this->addField($factory->createField(FieldFactory::TYPE_STRING, self::FIELD_QUERY, $query)); $this->addField($factory->createSubmitField(self::FIELD_SEARCH, self::TRANSLATION_SEARCH)); }
/** * Constructs a new module installation form * @param string $action URL where this form will point to * @return null */ public function __construct($action) { parent::__construct($action, self::NAME); $factory = FieldFactory::getInstance(); $this->addField($factory->createField(FieldFactory::TYPE_FILE, self::FIELD_MODULE)); $this->addField($factory->createSubmitField(self::FIELD_INSTALL, self::TRANSLATION_INSTALL)); $this->addValidator(self::FIELD_MODULE, new RequiredValidator()); }
/** * Construct a Google search form * @return null */ public function __construct() { parent::__construct(self::ACTION, self::NAME); $this->setMethod(Form::METHOD_GET); $this->setAttribute('target', '_blank'); $factory = FieldFactory::getInstance(); $this->addField($factory->createField(FieldFactory::TYPE_STRING, self::FIELD_QUERY)); $this->addField($factory->createSubmitField(self::FIELD_SUBMIT, self::TRANSLATION_SUBMIT)); }
/** * Constructs a new localize panel form * @return null */ public function __construct() { $request = Zibo::getInstance()->getRequest(); $factory = FieldFactory::getInstance(); parent::__construct($request->getBaseUrl() . Request::QUERY_SEPARATOR . Module::ROUTE_LOCALIZE, self::NAME); $this->removeFromClass(Form::STYLE_FORM); $localeCode = LocalizeController::getLocale(); $localeField = $factory->createField(FieldFactory::TYPE_LOCALE, self::FIELD_LOCALE, $localeCode); $this->addField($localeField); }
/** * Construct this form * @param string $action url where this form will point to * @param int $nodeId id of the node which contains a search result widget * @return null */ public function __construct($action, $nodeId = null) { parent::__construct($action, self::NAME); $factory = FieldFactory::getInstance(); $nodeField = $factory->createField(FieldFactory::TYPE_LIST, self::FIELD_NODE, $nodeId); $nodeField->setOptions($this->getNodeOptions()); $this->addField($nodeField); $this->addField($factory->createSubmitField(self::FIELD_SAVE, self::TRANSLATION_SAVE)); $this->addField($factory->createSubmitField(self::FIELD_CANCEL, self::TRANSLATION_CANCEL)); }
/** * Construct this form * @param string $action url where this form will point to * @param array $contentTypes Array with the name of searchable content types * @return null */ public function __construct($action, array $contentTypes = null) { parent::__construct($action, self::NAME); $factory = FieldFactory::getInstance(); $contentTypesField = $factory->createField(FieldFactory::TYPE_LIST, self::FIELD_CONTENT_TYPES, $contentTypes); $contentTypesField->setOptions($this->getSearchableContentTypeOptions()); $contentTypesField->setIsMultiple(true); $this->addField($contentTypesField); $this->addField($factory->createSubmitField(self::FIELD_SAVE, self::TRANSLATION_SAVE)); $this->addField($factory->createSubmitField(self::FIELD_CANCEL, self::TRANSLATION_CANCEL)); }
/** * Constructs a new cron process form * @param string $action URL where this form will point to * @param boolean $isRunning Flag to see if the cron process is currently running * @return null */ public function __construct($action, $isRunning) { parent::__construct($action, self::NAME); $fieldFactory = FieldFactory::getInstance(); if ($isRunning) { $translationKey = self::TRANSLATION_STOP; } else { $translationKey = self::TRANSLATION_START; } $submitButton = $fieldFactory->createSubmitField(self::BUTTON_SUBMIT, $translationKey); $this->addField($submitButton); }
/** * Constructs a new subscribe form * @param string $action URL where this form will point to * @return null */ public function __construct($action) { parent::__construct($action, self::NAME); $this->appendToClass('data'); $fieldFactory = FieldFactory::getInstance(); $emailField = $fieldFactory->createField(FieldFactory::TYPE_EMAIL, self::FIELD_EMAIL); $subscribeButton = $fieldFactory->createSubmitField(self::BUTTON_SUBSCRIBE, self::TRANSLATION_SUBSCRIBE); $this->addField($emailField); $this->addField($subscribeButton); $validatorFactory = ValidationFactory::getInstance(); $this->addValidator(self::FIELD_EMAIL, $validatorFactory->createValidator('required')); }
/** * Constructs a new done form * @param string $action URL where the form will point to * @param string $translationDone Translation key for the done button * @param string $formName Name of the form * @return null */ public function __construct($action, $translationDone = null, $formName = null) { if (!$formName) { $formName = self::NAME; } parent::__construct($action, $formName); if (!$translationDone) { $translationDone = self::TRANSLATION_DONE; } $doneField = FieldFactory::getInstance()->createSubmitField(self::BUTTON_DONE, $translationDone); $this->addField($doneField); }
/** * Construct a new form * @param string $action URL where the form will point to * @param string $name Name of the form * @param string $translationSubmit Translation key for the submit button * @param string $translationCancelTranslation key for the cancel button * @return null */ public function __construct($action, $name, $translationSubmit = null, $translationCancel = null) { parent::__construct($action, $name); $fieldFactory = FieldFactory::getInstance(); if (!$translationSubmit) { $translationSubmit = self::TRANSLATION_SUBMIT; } $submitButton = $fieldFactory->createSubmitField(self::BUTTON_SUBMIT, $translationSubmit); if (!$translationCancel) { $translationCancel = self::TRANSLATION_CANCEL; } $cancelButton = $fieldFactory->createSubmitField(self::BUTTON_CANCEL, $translationCancel); $this->addField($submitButton); $this->addField($cancelButton); }
/** * Constructs a new default database connection form * @param string $formAction URL where this form will point to * @param array $connections Available connections: array with Connection objects * @param zibo\database\admin\model\Connection $defaultConnection The default connection * @return null */ public function __construct($formAction, array $connections, Connection $defaultConnection) { parent::__construct($formAction, self::NAME); $defaultConnectionName = $defaultConnection->getName(); $connectionOptions = array(); foreach ($connections as $connection) { $connectionOptions[$connection->getName()] = $connection->getName(); } $fieldFactory = FieldFactory::getInstance(); $connectionField = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_DEFAULT, $defaultConnectionName); $connectionField->setOptions($connectionOptions); $saveButton = $fieldFactory->createSubmitField(self::BUTTON_SAVE, self::TRANSLATION_SAVE); $this->addField($connectionField); $this->addField($saveButton); }
/** * Construct this form * @param string $action url where this form will point to * @param joppa\model\Theme $theme the theme for which a region has to be selected * @param string $region optional name of a region to preselect * @return null */ public function __construct($action, Theme $theme, $region = null) { parent::__construct($action, self::NAME); $regions = array(); $themeRegions = $theme->getRegions(); foreach ($themeRegions as $name => $themeRegion) { $regions[$name] = $themeRegion->getName(); } $factory = FieldFactory::getInstance(); $field = $factory->createField(FieldFactory::TYPE_LIST, self::FIELD_REGION, $region); $field->setAttribute('onchange', 'this.form.submit()'); $field->setOptions($regions); $field->addEmpty('---', ''); $this->addField($field); }
/** * Construct this form * @param string $action url where the form will point to * @param joppa\model\Site $site optional site to preselect * @return null */ public function __construct($action, Site $site = null) { parent::__construct($action, self::NAME); $idSite = 0; if ($site != null) { $idSite = $site->id; } $siteModel = ModelManager::getInstance()->getModel('Site'); $this->siteList = $siteModel->getSiteList(); $fieldFactory = FieldFactory::getInstance(); $field = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_SITE, $idSite); $field->setOptions($this->siteList); $field->addEmpty(); $field->setAttribute('onchange', 'this.form.submit()'); $this->addField($field); }
/** * Constructs a new XML-RPC client form * @param string $action URL where this form will point to * @param string $server Hostname or IP address of the XML-RPC server * @param string $method The method or service to invoke * @param string $parameters String of the parameters * @return null * @see zibo\xmlrpc\parser\ParameterParser */ public function __construct($action, $server = null, $method = null, $parameters = null) { parent::__construct($action, self::NAME); $fieldFactory = FieldFactory::getInstance(); $serverField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_SERVER, $server); $serverField->addValidator(new WebsiteValidator()); $methodField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_METHOD, $method); $methodField->addValidator(new RequiredValidator()); $methodField->addValidator(new RegexValidator(array(RegexValidator::OPTION_REGEX => '/^([a-zA-Z0-9\\.]*)$/'))); $parametersField = $fieldFactory->createField(FieldFactory::TYPE_TEXT, self::FIELD_PARAMETERS, $parameters); $invokeButton = $fieldFactory->createSubmitField(self::BUTTON_INVOKE, self::TRANSLATION_INVOKE); $this->addField($serverField); $this->addField($methodField); $this->addField($parametersField); $this->addField($invokeButton); }
/** * Constructs a new contact form * @param string $action URL where this form will point to * @param string $name Name of the sender * @param string $email Email address of the sender * @param string $message Message of the sender * @return null */ public function __construct($action, $name = null, $email = null, $message = null) { parent::__construct($action, self::NAME); $fieldFactory = FieldFactory::getInstance(); $nameField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_NAME, $name); $emailField = $fieldFactory->createField(FieldFactory::TYPE_EMAIL, self::FIELD_EMAIL, $email); $messageField = $fieldFactory->createField(FieldFactory::TYPE_TEXT, self::FIELD_MESSAGE, $message); $submitButton = $fieldFactory->createSubmitField(self::BUTTON_SUBMIT, self::TRANSLATION_SUBMIT); $this->addField($nameField); $this->addField($emailField); $this->addField($messageField); $this->addField($submitButton); $requiredValidator = new RequiredValidator(); $this->addValidator(self::FIELD_NAME, $requiredValidator); $this->addValidator(self::FIELD_EMAIL, $requiredValidator); $this->addValidator(self::FIELD_MESSAGE, $requiredValidator); }
/** * Construct a new comment form * @param string $action URL where the form will point to * @param joppa\comment\model\data\CommentData $comment comment to preset the form * @return null */ public function __construct($action, CommentData $comment) { parent::__construct($action, self::NAME); $fieldFactory = FieldFactory::getInstance(); $idField = $fieldFactory->createField(FieldFactory::TYPE_HIDDEN, self::FIELD_ID, $comment->id); $parentField = $fieldFactory->createField(FieldFactory::TYPE_HIDDEN, self::FIELD_PARENT, $comment->parent); $versionField = $fieldFactory->createField(FieldFactory::TYPE_HIDDEN, self::FIELD_VERSION, $comment->version); $nameField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_NAME, $comment->name); $emailField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_EMAIL, $comment->email); $commentField = $fieldFactory->createField(FieldFactory::TYPE_TEXT, self::FIELD_COMMENT, $comment->comment); $submitButton = $fieldFactory->createSubmitField(self::BUTTON_SUBMIT, self::TRANSLATION_SUBMIT); $this->addField($idField); $this->addField($parentField); $this->addField($versionField); $this->addField($nameField); $this->addField($emailField); $this->addField($commentField); $this->addField($submitButton); }
/** * Validates this form * @return null * @throws zibo\library\validation\exception\ValidationException when one of the fields or the form itself is not validated */ public function validate() { try { parent::validate(); $validationException = new ValidationException(); } catch (ValidationException $exception) { $validationException = $exception; } foreach ($this->hooks as $hook) { try { $hook->onProfileFormValidate(); } catch (ValidationException $exception) { $allErrors = $exception->getAllErrors(); foreach ($allErrors as $field => $errors) { $validationException->addErrors($field, $errors); } } } if ($validationException->hasErrors()) { throw $validationException; } }
/** * Constructs a new forum search form * @param string $action URL where this form will point to * @param joppa\forum\model\data\ForumSearchData $data The data to preset the form * @return null */ public function __construct($action, ForumSearchData $data) { parent::__construct($action, self::NAME); $modelManager = ModelManager::getInstance(); $fieldFactory = FieldFactory::getInstance(); $categoryModel = $modelManager->getModel(ForumCategoryModel::NAME); $categories = $categoryModel->getCategories(); $queryField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_QUERY, $data->query); $boardField = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_CATEGORY, $data->category); $boardField->setIsMultiple(true); foreach ($categories as $category) { $boards = array(); foreach ($category->boards as $board) { $boards[$board->id] = $board->name; } $boardField->setOptions($boards, $category->name); } $searchButton = $fieldFactory->createSubmitField(self::BUTTON_SEARCH, self::TRANSLATION_SEARCH); $this->addField($queryField); $this->addField($boardField); $this->addField($searchField); }
/** * Gets the data object from the provided form * @param zibo\library\html\form\Form $form * @return mixed Data object */ protected function getFormData(Form $form) { return $form->getData(); }
/** * Construct a new wizard form * @param string $action URL where the form will point to * @param string $name Name of the form * @return null */ public function __construct($action, $name) { parent::__construct($action, $name); $this->appendToClass(self::STYLE_WIZARD); $fieldFactory = FieldFactory::getInstance(); $previousButton = $fieldFactory->createSubmitField(self::BUTTON_PREVIOUS, self::TRANSLATION_PREVIOUS); $nextButton = $fieldFactory->createSubmitField(self::BUTTON_NEXT, self::TRANSLATION_NEXT); $cancelButton = $fieldFactory->createSubmitField(self::BUTTON_CANCEL, self::TRANSLATION_CANCEL); $finishButton = $fieldFactory->createSubmitField(self::BUTTON_FINISH, self::TRANSLATION_FINISH); $this->addField($previousButton); $this->addField($nextButton); $this->addField($cancelButton); $this->addField($finishButton); $this->steps = array(); $this->session = Session::getInstance(); }
/** * Decorates the provided cron job * @param zibo\cron\model\CronJob $job Cron job to decorate * @return string */ protected function decorateCronJob(CronJob $job) { $button = $this->form->getField(CronJobTable::BUTTON_INVOKE); return $button->getOptionHtml($job->getId()); }
/** * Gets a view for the captcha part * @param zibo\library\html\form\Form $form Form with the captcha added * @return zibo\core\view\HtmlView */ public function getCaptchaView(Form $form) { $formId = $form->getId(); $error = null; if (array_key_exists($formId, $this->errors)) { $error = $this->errors[$formId]; } return new RecaptchaView($this->publicKey, $error); }
/** * Construct this form * @param string $action url where this form will point to * @param joppa\model\NodeSettings $settings * @return null */ public function __construct($action, NodeSettings $settings) { parent::__construct($action, self::NAME); $this->nodeSettings = $settings; $factory = FieldFactory::getInstance(); $translator = I18n::getInstance()->getTranslator(); $publishedField = $factory->createField(FieldFactory::TYPE_LIST, self::FIELD_PUBLISHED); $publishedField->setOptions($this->getPublishedOptions($translator)); $authenticationStatusField = $factory->createField(FieldFactory::TYPE_OPTION, self::FIELD_AUTHENTICATION_STATUS); $authenticationStatusField->setOptions($this->getAuthenticationStatusOptions($translator)); $permissionsField = $factory->createField(FieldFactory::TYPE_LIST, self::FIELD_PERMISSIONS); $permissionsField->setOptions($this->getPermissionOptions()); $permissionsField->setIsMultiple(true); $this->addField($publishedField); $this->addField($factory->createField(FieldFactory::TYPE_DATE, self::FIELD_PUBLISH_START)); $this->addField($factory->createField(FieldFactory::TYPE_DATE, self::FIELD_PUBLISH_STOP)); $this->addField($authenticationStatusField); $this->addField($permissionsField); $this->addField($factory->createSubmitField(self::FIELD_SAVE, 'button.save')); $this->addField($factory->createSubmitField(self::FIELD_CANCEL, 'button.cancel')); $this->setValues($this->nodeSettings); }