public function enable() { $el = $this->form->getElementPrototype(); if (!$el->name) { $el->name = 'frm-' . ($this->form instanceof AppForm ? $this->form->lookupPath('Nette\\Application\\Presenter', TRUE) : $this->form->getName()); } $this->validateScripts = array(); $this->toggleScript = ''; $this->central = TRUE; foreach ($this->form->getControls() as $control) { $script = $this->getValidateScript($control->getRules()); if ($script) { $this->validateScripts[$control->getHtmlName()] = $script; } $this->toggleScript .= $this->getToggleScript($control->getRules()); if ($control instanceof ISubmitterControl && $control->getValidationScope() !== TRUE) { $this->central = FALSE; } } if ($this->validateScripts || $this->toggleScript) { if ($this->central) { $this->form->getElementPrototype()->onsubmit("return nette.validateForm(this)", TRUE); } else { foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\ISubmitterControl') as $control) { if ($control->getValidationScope()) { $control->getControlPrototype()->onclick("return nette.validateForm(this)", TRUE); } } } } }
static function registerForm(Form $form) { self::$forms[$form->getName()] = $form; if (@$_REQUEST[FormSigner::ID_ELT] === $form->getName()) { $form->call(self::getSigner()); return true; } else { $form->init(); } return false; }
/** * render * * @return string */ public function render() { $editor_handler = \XoopsEditorHandler::getInstance(); $editor_handler->allowed_editors = $this->allowed_editors; $option_select = new Select("", $this->name, $this->value); $onchangeCode = '"if(this.options[this.selectedIndex].value.length > 0 ){window.document.forms.' . $this->form->getName() . '.submit();}"'; $option_select->set('onchange', $onchangeCode); $option_select->addOptionArray($editor_handler->getList($this->nohtml)); $this->addElement($option_select); return parent::render(); }
/** * Returns the body of the mail. * * @param bool $html Whether to return (X)HTML. * * @return string * * @global array The configuration of the core. */ protected function getBody($html) { global $cf; $o = ''; if ($html) { if ($cf['xhtml']['endtags'] == 'true') { $o .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional' . '//EN"' . ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . PHP_EOL . '<html xmlns="http://www.w3.org/1999/xhtml">' . PHP_EOL; } else { $o .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional' . '//EN"' . ' "http://www.w3.org/TR/html4/loose.dtd">' . PHP_EOL . '<html>' . PHP_EOL; } $o .= '<head>' . PHP_EOL . '<style type="text/css">' . PHP_EOL; $o .= $this->getMailCSS($this->pluginFolder . 'css/stylesheet.css'); $fn = Data::folder() . 'css/' . $this->form->getName() . '.css'; if (file_exists($fn)) { $o .= $this->getMailCSS($fn); } $o .= '</style>' . PHP_EOL . '</head>' . PHP_EOL . '<body>' . PHP_EOL; } $view = MailView::make($this->form, !$this->isConfirmation, $html); $o .= $view->render(); if ($html) { $o .= '</body>' . PHP_EOL . '</html>' . PHP_EOL; } return $o; }
/** * File fields have a diff name structure when posted back * @return string */ public function getFormFileName() { if ($this->getType() != self::TYPE_FILE || !is_object($this->form)) { return null; } return $this->form->getName() . '_' . $this->name; }
public function __construct(Form $form) { $this->form = $form; $name = ucfirst($form->getName()); //ucfirst(strtr($form->getUniqueId(), Form::NAME_SEPARATOR, '_')); $this->validateFunction = 'validate' . $name; $this->toggleFunction = 'toggle' . $name; }
/** * @param Form $form * * @return string */ public function generateFormID($form) { if ($id = $form->getHTMLID()) { return Convert::raw2htmlid($id); } $reflection = new ReflectionClass($form); $shortName = str_replace(array('.', '/'), '', $form->getName()); return Convert::raw2htmlid($reflection->getShortName() . '_' . $shortName); }
public function __construct(Form $form) { $this->form = $form; $this->name = str_replace("-", "_", ucfirst($form->getName())); //ucfirst(strtr($form->getUniqueId(), Form::NAME_SEPARATOR, '_')); $this->validateFunction = $this->name . '.validate'; $this->validateControlFunction = $this->name . '.validateControl'; $this->toggleFunction = $this->name . '.toggle'; $this->validateCalled = $this->name . '.validateCalled'; }
public function __construct() { parent::__construct(); $language = OW::getLanguage(); $form = new Form("change-user-password"); $form->setId("change-user-password"); $oldPassword = new PasswordField('oldPassword'); $oldPassword->setLabel($language->text('base', 'change_password_old_password')); $oldPassword->addValidator(new OldPasswordValidator()); $oldPassword->setRequired(); $form->addElement($oldPassword); $newPassword = new PasswordField('password'); $newPassword->setLabel($language->text('base', 'change_password_new_password')); $newPassword->setRequired(); $newPassword->addValidator(new NewPasswordValidator()); $form->addElement($newPassword); $repeatPassword = new PasswordField('repeatPassword'); $repeatPassword->setLabel($language->text('base', 'change_password_repeat_password')); $repeatPassword->setRequired(); $form->addElement($repeatPassword); $submit = new Submit("change"); $submit->setLabel($language->text('base', 'change_password_submit')); $form->setAjax(true); $form->addElement($submit); if (OW::getRequest()->isAjax()) { $result = false; if ($form->isValid($_POST)) { $data = $form->getValues(); BOL_UserService::getInstance()->updatePassword(OW::getUser()->getId(), $data['password']); $result = true; } echo json_encode(array('result' => $result)); exit; } else { $messageError = $language->text('base', 'change_password_error'); $messageSuccess = $language->text('base', 'change_password_success'); $js = " owForms['" . $form->getName() . "'].bind( 'success',\n function( json )\n {\n \tif( json.result == true )\n \t{\n \t \$('#TB_closeWindowButton').click();\n \t OW.info('{$messageSuccess}');\n }\n else\n {\n OW.error('{$messageError}');\n }\n\n } ); "; OW::getDocument()->addOnloadScript($js); $this->addForm($form); $language->addKeyForJs('base', 'join_error_password_not_valid'); $language->addKeyForJs('base', 'join_error_password_too_short'); $language->addKeyForJs('base', 'join_error_password_too_long'); //include js $onLoadJs = " window.changePassword = new OW_BaseFieldValidators( " . json_encode(array('formName' => $form->getName(), 'responderUrl' => OW::getRouter()->urlFor("BASE_CTRL_Join", "ajaxResponder"), 'passwordMaxLength' => UTIL_Validator::PASSWORD_MAX_LENGTH, 'passwordMinLength' => UTIL_Validator::PASSWORD_MIN_LENGTH)) . ",\n " . UTIL_Validator::EMAIL_PATTERN . ", " . UTIL_Validator::USER_NAME_PATTERN . " ); "; $onLoadJs .= " window.oldPassword = new OW_ChangePassword( " . json_encode(array('formName' => $form->getName(), 'responderUrl' => OW::getRouter()->urlFor("BASE_CTRL_Edit", "ajaxResponder"))) . " ); "; OW::getDocument()->addOnloadScript($onLoadJs); $jsDir = OW::getPluginManager()->getPlugin("base")->getStaticJsUrl(); OW::getDocument()->addScript($jsDir . "base_field_validators.js"); OW::getDocument()->addScript($jsDir . "change_password.js"); } }
/** * Builds a Form that mirrors the parent editForm, but with an extra field to collect the ChangeSet ID * * @param DataObject $object The object we're going to be adding to whichever ChangeSet is chosen * @return Form */ public function Form($object) { $inChangeSets = array_unique(ChangeSetItem::get_for_object($object)->column('ChangeSetID')); $changeSets = $this->getAvailableChangeSets()->map(); $campaignDropdown = DropdownField::create('Campaign', '', $changeSets); $campaignDropdown->setEmptyString(_t('Campaigns.AddToCampaign', 'Select a Campaign')); $campaignDropdown->addExtraClass('noborder'); $campaignDropdown->setDisabledItems($inChangeSets); $fields = new FieldList([$campaignDropdown, HiddenField::create('ID', null, $this->data['ID']), HiddenField::create('ClassName', null, $this->data['ClassName'])]); $form = new Form($this->editForm->getController(), $this->editForm->getName(), new FieldList($header = new CompositeField(new LiteralField('Heading', sprintf('<h3>%s</h3>', _t('Campaigns.AddToCampaign', 'Add To Campaign')))), $content = new CompositeField($fields)), new FieldList($action = AddToCampaignHandler_FormAction::create())); $header->addExtraClass('add-to-campaign__header'); $content->addExtraClass('add-to-campaign__content'); $action->addExtraClass('add-to-campaign__action'); $form->setHTMLID('Form_EditForm_AddToCampaign'); $form->unsetValidator(); $form->loadDataFrom($this->data); $form->addExtraClass('add-to-campaign__form'); return $form; }
/** * @param integer $userId */ public function __construct($userId) { parent::__construct(); $user = BOL_UserService::getInstance()->findUserById((int) $userId); if (!OW::getUser()->isAuthorized('base') || $user === null) { $this->setVisible(false); return; } $aService = BOL_AuthorizationService::getInstance(); $roleList = $aService->findNonGuestRoleList(); $form = new Form('give-role'); $form->setAjax(true); $form->setAction(OW::getRouter()->urlFor('BASE_CTRL_User', 'updateUserRoles')); $hidden = new HiddenField('userId'); $form->addElement($hidden->setValue($userId)); $userRoles = $aService->findUserRoleList($user->getId()); $userRolesIdList = array(); foreach ($userRoles as $role) { $userRolesIdList[] = $role->getId(); } $tplRoleList = array(); /* @var $role BOL_AuthorizationRole */ foreach ($roleList as $role) { $field = new CheckboxField('roles[' . $role->getId() . ']'); $field->setLabel(OW::getLanguage()->text('base', 'authorization_role_' . $role->getName())); $field->setValue(in_array($role->getId(), $userRolesIdList)); if (in_array($role->getId(), $userRolesIdList) && $role->getSortOrder() == 1) { $field->addAttribute('disabled', 'disabled'); } $form->addElement($field); $tplRoleList[$role->sortOrder] = $role; } ksort($tplRoleList); $form->addElement(new Submit('submit')); OW::getDocument()->addOnloadScript("owForms['{$form->getName()}'].bind('success', function(data){\n if( data.result ){\n if( data.result == 'success' ){\n window.baseChangeUserRoleFB.close();\n window.location.reload();\n //OW.info(data.message);\n }\n else if( data.result == 'error'){\n OW.error(data.message);\n }\n }\n\t\t})"); $this->addForm($form); $this->assign('list', $tplRoleList); }
/** * Returns the view of a form by instatiating the template. * * @return string (X)HTML. * * @global string The (X)HTML fragment for insertion into the HEAD element. * @global array The configuration of the plugins. */ protected function renderTemplate() { global $hjs, $plugin_cf; $fn = Data::folder() . 'css/' . $this->form->getName() . '.css'; if (file_exists($fn)) { $hjs .= tag('link rel="stylesheet" href="' . $fn . '" type="text/css"') . PHP_EOL; } $fn = Data::folder() . 'js/' . $this->form->getName() . '.js'; if (file_exists($fn)) { $hjs .= '<script type="text/javascript" src="' . $fn . '"></script>' . PHP_EOL; } $fn = Data::folder() . $this->form->getName() . '.tpl' . ($plugin_cf['advancedform']['php_extension'] ? '.php' : ''); $advfrm_script = file_get_contents($fn); foreach ($this->form->getFields() as $field) { $field = Field::make($field); $fieldView = new FieldView($this->form->getName(), $field); $advfrm_script = str_replace('<?field ' . $field->getName() . '?>', $fieldView->render(), $advfrm_script); } extract($GLOBALS); ob_start(); eval('?>' . $advfrm_script); return ob_get_clean(); }
/** * @covers Xoops\Form\Form::getName */ public function testGetName() { $value = $this->object->getName(); $this->assertSame('name', $value); }
/** * Returns a representation of the provided {@link Form} as structured data, * based on the request data. * * @param Form $form * @return array */ protected function getSchemaForForm(Form $form) { $request = $this->getRequest(); $schemaParts = []; $return = null; // Valid values for the "X-Formschema-Request" header are "schema" and "state". // If either of these values are set they will be stored in the $schemaParst array // and used to construct the response body. if ($schemaHeader = $request->getHeader('X-Formschema-Request')) { $schemaParts = array_filter(explode(',', $schemaHeader), function ($value) { $validHeaderValues = ['schema', 'state']; return in_array(trim($value), $validHeaderValues); }); } if (!count($schemaParts)) { throw new SS_HTTPResponse_Exception('Invalid request. Check you\'ve set a "X-Formschema-Request" header with "schema" or "state" values.', 400); } $return = ['id' => $form->getName()]; if (in_array('schema', $schemaParts)) { $return['schema'] = $this->schema->getSchema($form); } if (in_array('state', $schemaParts)) { $return['state'] = $this->schema->getState($form); } return $return; }
protected function initAttachments($feedAutoId, Form $form) { $attachmentInputId = $form->getElement('attachment')->getId(); $attachmentId = 'nfa-' . $feedAutoId; $inputId = $form->getElement('status')->getId(); $js = 'OWLinkObserver.observeInput("' . $inputId . '", function(link){ var ac = $("#attachment_preview_' . $attachmentId . '"); ac.show().html("<div class=\\"ow_preloader\\" style=\\"height: 30px;\\"></div>"); this.requestResult(function( r ) { ac.html(r); }); this.onResult = function( r ) { $("#' . $attachmentInputId . '").val(JSON.stringify(r)); }; });'; OW::getDocument()->addOnloadScript($js); $this->assign('uniqId', $attachmentId); $attachment = new BASE_CLASS_Attachment($attachmentId); $this->addComponent('attachment', $attachment); $js = 'owForms[{$form}].bind("success", function(data){ OW.trigger("base.init_attachment", {$uniqId}); owForms[{$form}].getElement("attachment").setValue(""); OWLinkObserver.getObserver("' . $inputId . '").resetObserver(); }); owForms[{$form}].reset = false; OW.bind("base.attachment_added", function(data){ if( data.uid == {$uniqId} ){ owForms[{$form}].getElement("attachment").setValue(JSON.stringify(data)); } } ); OW.bind("base.attachment_deleted", function(data){ if( data.uid == {$uniqId} ){ owForms[{$form}].getElement("attachment").setValue(""); OWLinkObserver.getObserver("' . $inputId . '").resetObserver(); } } );'; $js = UTIL_JsGenerator::composeJsString($js, array('form' => $form->getName(), 'uniqId' => $attachmentId)); OW::getDocument()->addOnloadScript($js); }
/** * Adds form to renderable object. * * @param Form $form */ public function addForm(Form $form) { $this->forms[$form->getName()] = $form; }
protected function initAttachments($feedAutoId, Form $form) { $attachmentInputId = $form->getElement('attachment')->getId(); $attachmentId = uniqid('nfa-' . $feedAutoId); $attachmentBtnId = $attachmentId . "-btn"; $inputId = $form->getElement('status')->getId(); $js = 'OWLinkObserver.observeInput("' . $inputId . '", function(link){ var ac = $("#attachment_preview_' . $attachmentId . '-oembed"); if ( ac.data("sleep") ) return; ac.show().html("<div class=\\"ow_preloader\\" style=\\"height: 30px;\\"></div>"); this.requestResult(function( r ) { ac.show().html(r); }); this.onResult = function( r ) { $("#' . $attachmentInputId . '").val(JSON.stringify(r)); }; });'; OW::getDocument()->addOnloadScript($js); $this->assign('uniqId', $attachmentId); $attachment = new BASE_CLASS_Attachment("newsfeed", $attachmentId, $attachmentBtnId); $this->addComponent('attachment', $attachment); $js = 'var attUid = {$uniqId}, uidUniq = 0; owForms[{$form}].bind("success", function(data){ OW.trigger("base.photo_attachment_reset", {pluginKey:"newsfeed", uid:attUid}); owForms[{$form}].getElement("attachment").setValue(""); OWLinkObserver.getObserver("' . $inputId . '").resetObserver(); $("#attachment_preview_" + {$uniqId} + "-oembed").data("sleep", false).empty(); var attOldUid = attUid; attUid = {$uniqId} + (uidUniq++); OW.trigger("base.photo_attachment_uid_update", { uid: attOldUid, newUid: attUid }); }); owForms[{$form}].reset = false; OW.bind("base.add_photo_attachment_submit", function(data){ if( data.uid == attUid ) { $("#attachment_preview_" + {$uniqId} + "-oembed").hide().empty(); $("#attachment_preview_" + {$uniqId} + "-oembed").data("sleep", true); } } ); OW.bind("base.attachment_hide_button_cont", function(data){ if( data.uid == attUid ) { $("#" + {$uniqId} + "-btn-cont").hide(); } } ); OW.bind("base.attachment_show_button_cont", function(data){ if( data.uid == attUid ) { $("#" + {$uniqId} + "-btn-cont").show(); } } ); OW.bind("base.attachment_added", function(data){ if( data.uid == attUid ) { data.type = "photo"; owForms[{$form}].getElement("attachment").setValue(JSON.stringify(data)); } } ); OW.bind("base.attachment_deleted", function(data){ if( data.uid == attUid ){ $("#attachment_preview_" + {$uniqId} + "-oembed").data("sleep", false).empty(); owForms[{$form}].getElement("attachment").setValue(""); OWLinkObserver.getObserver("' . $inputId . '").resetObserver(); } } );'; $js = UTIL_JsGenerator::composeJsString($js, array('form' => $form->getName(), 'uniqId' => $attachmentId)); OW::getDocument()->addOnloadScript($js); }