public function setValueFrom(DataObjectInterface $do) { if ($do->StreetName) { $this->streetNameField->setValue($do->StreetName); } if ($do->StreetNumber) { $this->streetNumberField->setValue($do->StreetNumber); } }
public function testDefaultValueIsRespected() { $field = new TextField('default_value', 0, 'default', array(), null); $this->assertEquals('(default)', $field->getEscapedValue(), "Default Value is respected on null value"); $field->setValue('value'); $this->assertEquals('(value)', $field->getEscapedValue(), "Default Value is ignored if value not null"); $field->setValue(''); $this->assertEquals('(\\)', $field->getEscapedValue(), "Default Value is ignored if value is empty"); }
public function settings() { $adminForm = new Form('adminForm'); $language = OW::getLanguage(); $config = OW::getConfig(); $element = new TextField('autoclick'); $element->setRequired(true); $validator = new IntValidator(1); $validator->setErrorMessage($language->text('autoviewmore', 'admin_invalid_number_error')); $element->addValidator($validator); $element->setLabel($language->text('autoviewmore', 'admin_auto_click')); $element->setValue($config->getValue('autoviewmore', 'autoclick')); $adminForm->addElement($element); $element = new Submit('saveSettings'); $element->setValue($language->text('autoviewmore', 'admin_save_settings')); $adminForm->addElement($element); if (OW::getRequest()->isPost()) { if ($adminForm->isValid($_POST)) { $values = $adminForm->getValues(); $config = OW::getConfig(); $config->saveConfig('autoviewmore', 'autoclick', $values['autoclick']); OW::getFeedback()->info($language->text('autoviewmore', 'user_save_success')); } } $this->addForm($adminForm); }
public function setValue($value) { foreach ($this->getExtraFieldsInit() as $field) { $field->setValue($value); } return parent::setValue($value); }
/** * Class constructor */ public function __construct($providerName) { parent::__construct('provider-config-form'); $this->setAjax(true); $this->bindJsFunction(Form::BIND_SUCCESS, 'function(data){if( data.result ){OW.info(data.message);setTimeout(function(){location.reload();}, 1000);}else{OW.error(data.message);}}'); $this->setAction(OW::getRouter()->urlForRoute('ynsocialconnect-admin-ajaxUpdateProfileQuestion')); $language = OW::getLanguage(); $service = YNSOCIALCONNECT_BOL_ServicesService::getInstance(); $questionDtoList = $service->getOWQuestionDtoList($providerName); $aliases = $service->findAliasList($providerName); $options = $service->getServiceFields($providerName); foreach ($questionDtoList as $question) { $new_element = new Selectbox('alias[' . $question->name . ']'); foreach ($options as $option) { $new_element->addOption($option->name, $option->label); } $new_element->setValue(empty($aliases[$question->name]) ? '' : $aliases[$question->name]); $this->addElement($new_element); } $hidden = new TextField('providerName'); $hidden->addAttribute('type', 'hidden'); $hidden->setValue($providerName); $this->addElement($hidden); $submit = new Submit('edit'); $submit->setValue($language->text('ynsocialconnect', 'save_btn_label')); $this->addElement($submit); }
/** * Class constructor * */ public function __construct($plugins) { parent::__construct('configForm'); $language = OW::getLanguage(); $values = OW::getConfig()->getValues('attachments'); if ($plugins['video']) { $field = new CheckboxField('video_share'); $field->setValue($values['video_share']); $this->addElement($field); } if ($plugins['links']) { $field = new CheckboxField('link_share'); $field->setValue($values['link_share']); $this->addElement($field); } if ($plugins['photo']) { $field = new CheckboxField('photo_share'); $field->setId('photo_share_check'); $field->setValue($values['photo_share']); $this->addElement($field); $field = new TextField('photo_album_name'); $field->setValue(OW::getLanguage()->text('attachments', 'default_photo_album_name')); $field->setRequired(); $this->addElement($field); } // submit $submit = new Submit('save'); $submit->setValue($language->text('attachments', 'config_save_label')); $this->addElement($submit); }
/** * Class constructor * */ public function __construct() { parent::__construct('configSaveForm'); $language = OW::getLanguage(); $field = new TextField('public_key'); $field->addValidator(new ConfigRequireValidator()); $this->addElement($field); $field = new CheckboxField('billing_enabled'); $this->addElement($field); // submit $submit = new Submit('save'); $submit->setValue($language->text('admin', 'save_btn_label')); $this->addElement($submit); $promoUrl = new TextField('app_url'); $promoUrl->setRequired(); $promoUrl->addValidator(new UrlValidator()); $promoUrl->setLabel($language->text('skandroid', 'app_url_label')); $promoUrl->setDescription($language->text('skandroid', 'app_url_desc')); $promoUrl->setValue(OW::getConfig()->getValue('skandroid', 'app_url')); $this->addElement($promoUrl); $smartBanner = new CheckboxField('smart_banner'); $smartBanner->setLabel($language->text('skandroid', 'smart_banner_label')); $smartBanner->setDescription($language->text('skandroid', 'smart_banner_desc')); $smartBanner->setValue(OW::getConfig()->getValue('skandroid', 'smart_banner')); $this->addElement($smartBanner); }
public function __construct() { parent::__construct('payeer-config-form'); $language = OW::getLanguage(); $billingService = BOL_BillingService::getInstance(); $gwKey = BILLINGPAYEER_CLASS_PayeerAdapter::GATEWAY_KEY; $element = new TextField('m_key'); $element->setValue($billingService->getGatewayConfigValue($gwKey, 'm_key')); $this->addElement($element); $element = new TextField('m_shop'); $element->setValue($billingService->getGatewayConfigValue($gwKey, 'm_shop')); $this->addElement($element); $element = new Selectbox('m_curr'); $element->setValue($billingService->getGatewayConfigValue($gwKey, 'm_curr'))->setHasInvitation(false)->addOption('RUB', 'RUB')->addOption('usd', 'USD'); $this->addElement($element); $element = new Selectbox('lang'); $element->setValue($billingService->getGatewayConfigValue($gwKey, 'lang'))->setHasInvitation(false)->addOption('ru', 'Русский')->addOption('en', 'English'); $this->addElement($element); $element = new Selectbox('tabNum'); $element->setValue($billingService->getGatewayConfigValue($gwKey, 'tabNum'))->setHasInvitation(false)->addOption('1', 'Electronic Systems')->addOption('2', 'Cash / Bank Transfers')->addOption('3', 'Terminals')->addOption('4', 'SMS payments'); $this->addElement($element); // submit $submit = new Submit('save'); $submit->setValue($language->text('billingpayeer', 'btn_save')); $this->addElement($submit); }
public function index() { $language = OW::getLanguage(); $billingService = BOL_BillingService::getInstance(); $adminForm = new Form('adminForm'); $element = new TextField('creditValue'); $element->setRequired(true); $element->setLabel($language->text('billingcredits', 'admin_usd_credit_value')); $element->setDescription($language->text('billingcredits', 'admin_usd_credit_value_desc')); $element->setValue($billingService->getGatewayConfigValue('billingcredits', 'creditValue')); $validator = new FloatValidator(0.1); $validator->setErrorMessage($language->text('billingcredits', 'invalid_numeric_format')); $element->addValidator($validator); $adminForm->addElement($element); $element = new Submit('saveSettings'); $element->setValue($language->text('billingcredits', 'admin_save_settings')); $adminForm->addElement($element); if (OW::getRequest()->isPost()) { if ($adminForm->isValid($_POST)) { $values = $adminForm->getValues(); $billingService->setGatewayConfigValue('billingcredits', 'creditValue', $values['creditValue']); OW::getFeedback()->info($language->text('billingcredits', 'user_save_success')); } } $this->addForm($adminForm); $this->setPageHeading(OW::getLanguage()->text('billingcredits', 'config_page_heading')); $this->setPageTitle(OW::getLanguage()->text('billingcredits', 'config_page_heading')); $this->setPageHeadingIconClass('ow_ic_app'); }
function __construct($controller, $name) { $fields = new FieldList(array($t1 = new TextField('ExternalOrderId', 'Eventbrite Order #'), $checkbox = new CheckboxField('SharedContactInfo', 'Allow to share contact info?'))); $t1->setAttribute('placeholder', 'Enter your Eventbrite order #'); $t1->addExtraClass('event-brite-order-number'); $attendees = Session::get('attendees'); if (count($attendees) > 0) { $t1->setValue(Session::get('ExternalOrderId')); $t1->setReadonly(true); $checkbox->setValue(intval(Session::get('SharedContactInfo')) === 1); $fields->add(new LiteralField('ctrl1', 'Current Order has following registered attendees, please select one:')); $options = array(); foreach ($attendees as $attendee) { $ticket_external_id = intval($attendee['ticket_class_id']); $ticket_type = SummitTicketType::get()->filter('ExternalId', $ticket_external_id)->first(); if (is_null($ticket_type)) { continue; } $options[$attendee['id']] = $attendee['profile']['name'] . ' (' . $ticket_type->Name . ')'; } $attendees_ctrl = new OptionSetField('SelectedAttendee', '', $options); $fields->add($attendees_ctrl); $validator = new RequiredFields(array('ExternalOrderId')); // Create action $actions = new FieldList($btn_clear = new FormAction('clearSummitAttendeeInfo', 'Clear'), $btn = new FormAction('saveSummitAttendeeInfo', 'Done')); $btn->addExtraClass('btn btn-default active'); $btn_clear->addExtraClass('btn btn-danger active'); } else { $validator = new RequiredFields(array('ExternalOrderId')); // Create action $actions = new FieldList($btn = new FormAction('saveSummitAttendeeInfo', 'Get Order')); $btn->addExtraClass('btn btn-default active'); } parent::__construct($controller, $name, $fields, $actions, $validator); }
function __construct($controller, $name, $talkID) { // Email Address Field $EmailAddressField = new TextField('Email', "Speaker's Email Address"); $formData = Session::get("FormInfo.Form_CallForSpeakersRegistrationForm.data"); if ($formData['Email']) { $email = $formData['Email']; } else { $email = Member::currentUser()->Email; } $EmailAddressField->setValue($email); // Talk ID $TalkField = new HiddenField('TalkID', "TalkID", $talkID); $fields = new FieldList($EmailAddressField, $TalkField); $talk = NULL; if ($talkID != NULL) { // Look to see if the presentation has at least one speaker attached $talkID = Convert::raw2sql($talkID); $talk = Talk::get()->byID($talkID); } if ($talk && $talk->HasSpeaker()) { $actions = new FieldList(new FormAction('addAction', 'Add New Speaker'), new FormAction('done', 'Done Editing Speakers')); } else { $actions = new FieldList(new FormAction('addAction', 'Add First Speaker')); } parent::__construct($controller, $name, $fields, $actions); }
/** * Class constructor * */ public function __construct($configs) { parent::__construct('configSaveForm'); $language = OW::getLanguage(); $field = new RadioField('itunes_mode'); $field->setOptions(array("test" => $language->text("skadateios", "itunes_mode_test"), "live" => $language->text("skadateios", "itunes_mode_live"))); $field->setValue($configs["itunes_mode"]); $this->addElement($field); $field = new CheckboxField('billing_enabled'); $field->setValue($configs["billing_enabled"]); $this->addElement($field); $field = new TextField('itunes_secret'); $field->addValidator(new ConfigRequireValidator()); $field->setValue($configs["itunes_secret"]); $this->addElement($field); $promoUrl = new TextField('app_url'); $promoUrl->setRequired(); $promoUrl->addValidator(new UrlValidator()); $promoUrl->setLabel($language->text('skadateios', 'app_url_label')); $promoUrl->setDescription($language->text('skadateios', 'app_url_desc')); $promoUrl->setValue($configs['app_url']); $this->addElement($promoUrl); $smartBanner = new CheckboxField('smart_banner'); $smartBanner->setLabel($language->text('skadateios', 'smart_banner_label')); $smartBanner->setDescription($language->text('skadateios', 'smart_banner_desc')); $smartBanner->setValue($configs['smart_banner']); $this->addElement($smartBanner); // submit $submit = new Submit('save'); $submit->setValue($language->text('admin', 'save_btn_label')); $this->addElement($submit); }
public function __construct($albumId) { parent::__construct('albumEditForm'); $album = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($albumId); $this->setAction(OW::getRouter()->urlForRoute('photo.ajax_update_photo')); $this->setAjax(TRUE); $this->setAjaxResetOnSuccess(FALSE); $albumIdField = new HiddenField('album-id'); $albumIdField->setValue($album->id); $albumIdField->setRequired(); $albumIdField->addValidator(new PHOTO_CLASS_AlbumOwnerValidator()); $this->addElement($albumIdField); $albumNameField = new TextField('albumName'); $albumNameField->setValue($album->name); $albumNameField->setRequired(); if ($album->name != trim(OW::getLanguage()->text('photo', 'newsfeed_album'))) { $albumNameField->addValidator(new PHOTO_CLASS_AlbumNameValidator(TRUE, NULL, $album->name)); } $albumNameField->addAttribute('class', 'ow_photo_album_name_input'); $this->addElement($albumNameField); $desc = new Textarea('desc'); $desc->setValue(!empty($album->description) ? $album->description : NULL); $desc->setHasInvitation(TRUE); $desc->setInvitation(OW::getLanguage()->text('photo', 'describe_photo')); $desc->addAttribute('class', 'ow_photo_album_description_textarea'); $this->addElement($desc); }
public function __construct($conversationId, $opponentId) { parent::__construct('newMailMessageForm'); $this->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA); $field = new TextField('newMessageText'); $field->setValue(OW::getLanguage()->text('mailbox', 'text_message_invitation')); $field->setId('newMessageText'); $this->addElement($field); $field = new HiddenField('attachment'); $this->addElement($field); $field = new HiddenField('conversationId'); $field->setValue($conversationId); $this->addElement($field); $field = new HiddenField('opponentId'); $field->setValue($opponentId); $this->addElement($field); $field = new HiddenField('uid'); $field->setValue(UTIL_HtmlTag::generateAutoId('mailbox_conversation_' . $conversationId . '_' . $opponentId)); $this->addElement($field); $submit = new Submit('newMessageSendBtn'); $submit->setId('newMessageSendBtn'); $submit->setName('newMessageSendBtn'); $submit->setValue(OW::getLanguage()->text('mailbox', 'add_button')); $this->addElement($submit); if (!OW::getRequest()->isAjax()) { $js = UTIL_JsGenerator::composeJsString(' owForms["newMailMessageForm"].bind( "submit", function( r ) { $("#newmessage-mail-send-btn").addClass("owm_preloader_circle"); });'); OW::getDocument()->addOnloadScript($js); } $this->setAction(OW::getRouter()->urlFor('MAILBOX_MCTRL_Messages', 'newmessage')); }
/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $field = new TextField($question->name(), $question->label()); $field->setValue($question->initialValue()); if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setAttribute('data-rule-required', 'true'); } if (!is_null($answer)) { $field->setValue($answer->value()); } $this->buildDependantRules($current_step, $question, $field); return $field; }
/** * @param array $value * @param DataObjectInterface $record */ public function setValue($value, $record = null) { if ($record && is_object($record)) { $this->addressField->setValue($record->{$this->getName()}); foreach ($this->getManualFields() as $field) { $name = $this->getNestedFieldName($field); $field->setValue($record->{$name}); } } else { if (is_array($value)) { if (isset($value['Address'])) { $this->addressField->setValue($value['Address']); } foreach ($this->getManualFields() as $field) { $nested = $this->getNestedFieldName($field); if (isset($value[$nested])) { $field->setValue($value[$nested]); } } } else { if (is_string($value)) { $this->addressField->setValue($value); } } } }
public function __construct($albumId) { parent::__construct(self::FORM_NAME); $album = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($albumId); $this->setAction(OW::getRouter()->urlForRoute('photo.ajax_update_photo')); $this->setAjax(true); $this->setAjaxResetOnSuccess(false); $albumIdField = new HiddenField(self::ELEMENT_ALBUM_ID); $albumIdField->setValue($album->id); $albumIdField->setRequired(); $albumIdField->addValidator(new PHOTO_CLASS_AlbumOwnerValidator()); $this->addElement($albumIdField); $albumNameField = new TextField(self::ELEMENT_ALBUM_NAME); $albumNameField->setValue($album->name); $albumNameField->setRequired(); if ($album->name != trim(OW::getLanguage()->text('photo', 'newsfeed_album'))) { $albumNameField->addValidator(new PHOTO_CLASS_AlbumNameValidator(true, null, $album->name)); } $albumNameField->addAttribute('class', 'ow_photo_album_name_input'); $this->addElement($albumNameField); $desc = new Textarea(self::ELEMENT_DESC); $desc->setValue(!empty($album->description) ? $album->description : NULL); $desc->setHasInvitation(TRUE); $desc->setInvitation(OW::getLanguage()->text('photo', 'describe_photo')); $desc->addAttribute('class', 'ow_photo_album_description_textarea'); $this->addElement($desc); $this->triggerReady(array('albumId' => $albumId)); }
public function index($params = array()) { $userService = BOL_UserService::getInstance(); $language = OW::getLanguage(); $this->setPageHeading($language->text('hotlist', 'admin_heading_settings')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); $settingsForm = new Form('settingsForm'); $settingsForm->setId('settingsForm'); $expiration_time = new TextField('expiration_time'); $expiration_time->setRequired(); $expiration_time->setLabel($language->text('hotlist', 'label_expiration_time')); $expiration_time_value = (int) OW::getConfig()->getValue('hotlist', 'expiration_time') / 86400; $expiration_time->setValue($expiration_time_value); $settingsForm->addElement($expiration_time); $submit = new Submit('save'); $submit->addAttribute('class', 'ow_ic_save'); $submit->setValue($language->text('hotlist', 'label_save_btn_label')); $settingsForm->addElement($submit); $this->addForm($settingsForm); if (OW::getRequest()->isPost()) { if ($settingsForm->isValid($_POST)) { $data = $settingsForm->getValues(); OW::getConfig()->saveConfig('hotlist', 'expiration_time', $data['expiration_time'] * 86400); OW::getFeedback()->info($language->text('hotlist', 'settings_saved')); $this->redirect(); } } }
/** * Rebuild url on save * @param string $url */ public function setValue($url) { if ($url) { $url = $this->rebuildURL($url); } parent::setValue($url); }
/** * Class constructor * */ public function __construct() { parent::__construct('configSaveForm'); $language = OW::getLanguage(); $configs = OW::getConfig()->getValues('googlelocation'); $element = new TextField('api_key'); $element->setValue($configs['api_key']); $validator = new StringValidator(0, 40); $validator->setErrorMessage($language->text('googlelocation', 'api_key_too_long')); $element->addValidator($validator); $this->addElement($element); $options = array(GOOGLELOCATION_BOL_LocationService::DISTANCE_UNITS_MILES => $language->text('googlelocation', 'miles'), GOOGLELOCATION_BOL_LocationService::DISTANCE_UNITS_KM => $language->text('googlelocation', 'kms')); $distanseUnits = new Selectbox('distanse_units'); $distanseUnits->setOptions($options); $distanseUnits->setValue(GOOGLELOCATION_BOL_LocationService::getInstance()->getDistanseUnits()); $distanseUnits->setHasInvitation(false); $this->addElement($distanseUnits); $restrictions = new Selectbox('country_restriction'); $restrictions->setValue(!empty($configs['country_restriction']) ? $configs['country_restriction'] : null); $restrictions->setOptions($this->countryList); $restrictions->setInvitation(OW::getLanguage()->text('googlelocation', 'no_country_restriction')); $this->addElement($restrictions); $autofill = OW::getConfig()->getValue('googlelocation', 'auto_fill_location_on_search'); $autoFillLocationOnSearch = new CheckboxField('auto_fill_location_on_search'); $autoFillLocationOnSearch->setValue(empty($autofill) || $autofill == '0' ? false : $autofill); $this->addElement($autoFillLocationOnSearch); // submit $submit = new Submit('save'); $submit->setValue($language->text('base', 'edit_button')); $this->addElement($submit); }
public function __construct($configs, $features) { parent::__construct('MCOMPOSE_ConfigForm'); $this->configs = $configs; $language = OW::getLanguage(); $field = new TextField('max_users'); $field->setRequired(); $field->setValue($configs['max_users']); $this->addElement($field); if ($features["friends"]) { $field = new CheckboxField('friends_enabled'); $field->setValue($configs['friends_enabled']); $this->addElement($field); } if ($features["groups"]) { $field = new CheckboxField('groups_enabled'); $field->setValue($configs['groups_enabled']); $this->addElement($field); } if ($features["events"]) { $field = new CheckboxField('events_enabled'); $field->setValue($configs['events_enabled']); $this->addElement($field); } // submit $submit = new Submit('save'); $submit->setValue($language->text('mcompose', 'admin_save_btn')); $this->addElement($submit); }
/** * Tests the TextField Max Length Validation Success */ public function testMaxLengthValidationSuccess() { $textField = new TextField('TestField'); $textField->setMaxLength(5); $textField->setValue("John"); // 4 characters, so should pass $result = $textField->validate(new RequiredFields()); $this->assertTrue($result); }
public function setValue($value, $source = null) { if ($source instanceof DataObject) { $name = $this->getName(); $email = $source->{$name}()->Email; $this->member_id = $source->{$name}()->ID; parent::setValue($email); } }
/** * HTML for the column, content of the <td> element. * * @param GridField $gridField * @param DataObject $record - Record displayed in this row * @param string $columnName * @return string - HTML for the column. Return NULL to skip. */ public function getColumnContent($gridField, $record, $columnName) { $field = new TextField('MetaTitle'); $value = $gridField->getDataFieldValue($record, $columnName); $value = $this->formatValue($gridField, $record, $columnName, $value); $field->setName($this->getFieldName($field->getName(), $gridField, $record)); $field->setValue($value); return $field->Field() . $this->getErrorMessages(); }
/** * @param IRSVP $rsvp * @param IRSVPQuestionTemplate $question * @param IRSVPAnswer $answer * @return FormField */ public function build(IRSVP $rsvp, IRSVPQuestionTemplate $question, IRSVPAnswer $answer) { $field = new TextField($question->name(), $question->label()); if ($rsvp) { $field->setValue($rsvp->findAnswerByQuestion($question)->Value); } else { $field->setValue($question->initialValue()); } if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setAttribute('data-rule-required', 'true'); } if (!is_null($answer)) { $field->setValue($answer->value()); } return $this->buildDependantRules($rsvp, $question, $field); }
/** * @param ITrackQuestionTemplate $question * @param ITrackAnswer $answer * @return FormField */ public function build(ITrackQuestionTemplate $question, ITrackAnswer $answer) { $field = new TextField($question->name(), $question->label()); $field->setFieldHolderTemplate('BootstrapFieldHolder'); if (!is_null($answer)) { $field->setValue($answer->value()); } else { $field->setValue($question->initialValue()); } if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setAttribute('data-rule-required', 'true'); } if (!is_null($answer)) { $field->setValue($answer->value()); } return $field; }
public function setValue($value) { if (is_numeric($value)) { parent::setValue($value); } else { if (strlen($value) > 0) { parent::setValue(strtotime($value)); } else { parent::setValue(""); } } return $this; }
/** * Class constructor * */ public function __construct() { parent::__construct('configForm'); $language = OW::getLanguage(); $field = new TextField('photo_album_name'); $field->setValue(OW::getLanguage()->text('uavatars', 'default_photo_album_name')); $field->setRequired(); $this->addElement($field); // submit $submit = new Submit('save'); $submit->setValue($language->text('uavatars', 'config_save_label')); $this->addElement($submit); }
public function index($params) { $this->setPageTitle(OW::getLanguage()->text('spdownload', 'category_index_page_title')); $this->setPageHeading(OW::getLanguage()->text('spdownload', 'category_index_page_heading')); $category = array(); if (!empty($params) && isset($params['categoryId'])) { $category = SPDOWNLOAD_BOL_CategoryDao::getInstance()->findById($params['categoryId']); } $downloads = SPDOWNLOAD_BOL_CategoryService::getInstance()->getCategoryList(); $downloadCategories = array(); foreach ($downloads as $key => $value) { $downloadCategories[$value->id] = $value->name; } $form = new Form('add_category'); $this->addForm($form); // Create selectbox $fieldTo = new SelectBox('parent_category'); foreach ($downloadCategories as $key => $label) { $fieldTo->addOption($key, $label); } if (!empty($params) && isset($params['categoryId'])) { $fieldTo->setValue($category->parentId); } $fieldTo->setLabel(OW::getLanguage()->text('spdownload', 'ad_parent_category')); $form->addElement($fieldTo); $fieldCate = new TextField('category'); $fieldCate->setLabel(OW::getLanguage()->text('spdownload', 'ad_label_category')); if (!empty($params) && isset($params['categoryId'])) { $fieldCate->setValue($category->name); } $fieldCate->setRequired(); $fieldCate->setHasInvitation(true); $form->addElement($fieldCate); $submit = new Submit('add'); $submit->setValue(OW::getLanguage()->text('spdownload', 'form_add_category_submit')); $form->addElement($submit); if (OW::getRequest()->isPost()) { if ($form->isValid($_POST)) { $data = $form->getValues(); if ($data['parent_category'] == null) { $data['parent_category'] = 0; } if (!empty($params) && isset($params['categoryId'])) { SPDOWNLOAD_BOL_CategoryService::getInstance()->addCategory($data['category'], $data['parent_category'], $params['categoryId']); } else { SPDOWNLOAD_BOL_CategoryService::getInstance()->addCategory($data['category'], $data['parent_category']); } $this->redirect(OW::getRouter()->urlForRoute('spdownload.category_list')); } } }
/** * Constructor * * @param Controller $controller The parent controller, necessary to * create the appropriate form action tag. * @param string $name The method on the controller that will return this * form object. * @param FieldList|FormField $fields All of the fields in the form - a * {@link FieldList} of {@link FormField} * objects. * @param FieldList|FormAction $actions All of the action buttons in the * form - a {@link FieldList} of * {@link FormAction} objects * @param bool $checkCurrentUser If set to TRUE, it will be checked if a * the user is currently logged in, and if * so, only a logout button will be rendered * @param string $authenticatorClassName Name of the authenticator class that this form uses. */ public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) { // This is now set on the class directly to make it easier to create subclasses // $this->authenticator_class = $authenticatorClassName; $customCSS = project() . '/css/member_login.css'; if (Director::fileExists($customCSS)) { Requirements::css($customCSS); } if (isset($_REQUEST['BackURL'])) { $backURL = $_REQUEST['BackURL']; } else { $backURL = Session::get('BackURL'); } if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) { $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this)); $actions = new FieldList(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else"))); } else { if (!$fields) { $label = singleton('Member')->fieldLabel(Member::config()->unique_identifier_field); $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this), $emailField = new TextField("Email", $label, null, null, $this), new PasswordField("Password", _t('Member.PASSWORD', 'Password'))); if (Security::config()->remember_username) { $emailField->setValue(Session::get('SessionForms.MemberLoginForm.Email')); } else { // Some browsers won't respect this attribute unless it's added to the form $this->setAttribute('autocomplete', 'off'); $emailField->setAttribute('autocomplete', 'off'); } if (Security::config()->autologin_enabled) { $fields->push(CheckboxField::create("Remember", _t('Member.KEEPMESIGNEDIN', "Keep me signed in"))->setAttribute('title', sprintf(_t('Member.REMEMBERME', "Remember me next time? (for %d days on this device)"), Config::inst()->get('RememberLoginHash', 'token_expiry_days')))); } } if (!$actions) { $actions = new FieldList(new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in")), new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>')); } } if (isset($backURL)) { $fields->push(new HiddenField('BackURL', 'BackURL', $backURL)); } // Reduce attack surface by enforcing POST requests $this->setFormMethod('POST', true); parent::__construct($controller, $name, $fields, $actions); $this->setValidator(new RequiredFields('Email', 'Password')); // Focus on the email input when the page is loaded $js = <<<JS \t\t\t(function() { \t\t\t\tvar el = document.getElementById("MemberLoginForm_LoginForm_Email"); \t\t\t\tif(el && el.focus && (typeof jQuery == 'undefined' || jQuery(el).is(':visible'))) el.focus(); \t\t\t})(); JS; Requirements::customScript($js, 'MemberLoginFormFieldFocus'); }