本文整理汇总了PHP中FormResponse类的典型用法代码示例。如果您正苦于以下问题:PHP FormResponse类的具体用法?PHP FormResponse怎么用?PHP FormResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Overloaded so that form error messages are displayed.
*
* @see OrderFormValidator::php()
* @see Form::validate()
*/
function validate()
{
if ($this->validator) {
$errors = $this->validator->validate();
if ($errors) {
if (Director::is_ajax() && $this->validator->getJavascriptValidationHandler() == 'prototype') {
FormResponse::status_message(_t('Form.VALIDATIONFAILED', 'Validation failed'), 'bad');
foreach ($errors as $error) {
FormResponse::add(sprintf("validationError('%s', '%s', '%s');\n", Convert::raw2js($error['fieldName']), Convert::raw2js($error['message']), Convert::raw2js($error['messageType'])));
}
} else {
$data = $this->getData();
$formError = array();
if ($formMessageType = $this->MessageType()) {
$formError['message'] = $this->Message();
$formError['messageType'] = $formMessageType;
}
// Load errors into session and post back
Session::set("FormInfo.{$this->FormName()}", array('errors' => $errors, 'data' => $data, 'formError' => $formError));
}
return false;
}
}
return true;
}
示例2: run
function run(DataObjectSet $pages)
{
$pageIDs = $pages->column('ID');
foreach ($pageIDs as $pageID) {
FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$pageID});");
}
$this->batchaction($pages, 'batchApprove', _t('BatchApprovePages.APPROVED_PAGES', 'Approved %d pages, %d failures'));
return FormResponse::respond();
}
示例3: saveInto
public function saveInto($record)
{
$data = $this->form->getRecord();
// if the record was written for the first time (has an arbitrary "new"-ID),
// update the imagefield to enable uploading
if ($record->ID && $data && substr($data->ID, 0, 3) == 'new') {
FormResponse::update_dom_id($this->id(), $this->Field($record->ID));
}
}
示例4: checkFolder
function checkFolder()
{
if (!$this->RootFolderID) {
$galleries = Folder::findOrMake('image-gallery');
$galleries->Title = 'Image Gallery';
$galleries->write();
$folder = Folder::findOrMake('image-gallery/' . $this->URLSegment);
$folder->Title = $this->Title;
$folder->setName($this->Title);
$folder->write();
$this->RootFolderID = $folder->ID;
$this->write();
$this->requireDefaultAlbum();
FormResponse::add("\$( 'Form_EditForm' ).getPageFromServer( {$this->ID} );");
} else {
$this->RootFolder()->setName($this->Title);
$this->RootFolder()->write();
}
}
示例5: publish
public function publish($comment, $member, $notify)
{
if (!$member) {
$member = Member::currentUser();
}
// We have to mark as completed now, or we'll get
// recursion from SiteTreeCMSWorkflow::onAfterPublish.
$this->Status = 'Completed';
$this->PublisherID = $member->ID;
$this->write();
$page = $this->Page();
$page->doDeleteFromLive();
// @todo Coupling to UI :-(
FormResponse::add(LeftAndMain::deleteTreeNodeJS($page));
if ($notify) {
// notify
}
return _t('SiteTreeCMSWorkflow.PUBLISHMESSAGE', 'Published changes to live version. Emailed %s.');
}
示例6: run
function run(DataObjectSet $pages)
{
$pageIDs = $pages->column('ID');
foreach ($pageIDs as $pageID) {
FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$pageID});");
}
$count = array();
$count['PUBLISH_SUCCESS'] = $count['DELETE_SUCCESS'] = 0;
$count['PUBLISH_FAILURE'] = $count['DELETE_FAILURE'] = 0;
$arbitraryPage = $pages->First();
$arbitraryPage->invokeWithExtensions('onBeforeBatchPublish', $pages);
foreach ($pages as $page) {
$type = $page->openWorkflowRequest() instanceof WorkflowDeletionRequest ? 'DELETE' : 'PUBLISH';
if ($page->batchPublish()) {
$count[$type . '_SUCCESS']++;
// Now make sure the tree title is appropriately updated
$publishedRecord = DataObject::get_by_id('SiteTree', $page->ID);
if ($publishedRecord) {
$JS_title = Convert::raw2js($publishedRecord->TreeTitle());
FormResponse::add("\$('sitetree').setNodeTitle({$page->ID}, '{$JS_title}');");
}
} else {
$count[$type . '_FAILURE']++;
FormResponse::add("\$('sitetree').addNodeClassByIdx('{$page->ID}', 'failed');");
}
$page->destroy();
unset($page);
}
$arbitraryPage->invokeWithExtensions('onAfterBatchPublish', $pages);
$messages = array('PUBLISH_SUCCESS' => _t('BatchPublishPages.PUBLISH_SUCCESS', 'Published %d pages.'), 'PUBLISH_FAILURE' => _t('BatchPublishPages.PUBLISH_FAILURE', 'Failed to publish %d pages.'), 'DELETE_SUCCESS' => _t('BatchPublishPages.DELETE_SUCCESS', 'Deleted %d pages from the published site.'), 'DELETE_FAILURE' => _t('BatchPublishPages.DELETE_FAILURE', 'Failed to delete %d pages from the published site.'), 'PUBLISH_SUCCESS_ONE' => _t('BatchPublishPages.PUBLISH_SUCCESS_ONE', 'Published %d page.'), 'PUBLISH_FAILURE_ONE' => _t('BatchPublishPages.PUBLISH_FAILURE_ONE', 'Failed to publish %d page.'), 'DELETE_SUCCESS_ONE' => _t('BatchPublishPages.DELETE_SUCCESS_ONE', 'Deleted %d page from the published site.'), 'DELETE_FAILURE_ONE' => _t('BatchPublishPages.DELETE_FAILURE_ONE', 'Failed to delete %d page from the published site.'));
$displayedMessages = array();
foreach ($count as $type => $count) {
if ($count) {
$message = $count == 1 ? $messages[$type . '_ONE'] : $messages[$type];
$displayedMessages[] = sprintf($message, $count);
}
}
$displayedMessage = implode(" ", $displayedMessages);
FormResponse::add('statusMessage("' . $displayedMessage . '","good");');
return FormResponse::respond();
}
示例7: moderate
function moderate()
{
$id = (int) $this->urlParams['ID'];
$className = Convert::raw2sql($this->urlParams['ClassName']);
$state = Convert::raw2sql($this->urlParams['State']);
$methods = array("delete" => "moderatorDelete", "isspam" => "markSpam", "isham" => "markHam", "approve" => "markApproved", "unapprove" => "markUnapproved");
ModeratableState::push_state($state);
$method = $methods[$this->urlParams['Command']];
if (!$method) {
FormResponse::clear();
FormResponse::status_message("Command invalid", 'bad');
} else {
if ($error = DataObject::get_by_id($className, $id)->{$method}()) {
FormResponse::status_message($error, 'bad');
} else {
FormResponse::add('$("moderation").elementMoved(' . $id . ');');
}
}
ModeratableState::pop_state();
return FormResponse::respond();
}
示例8: doPublish
/**
* When an error page is published, create a static HTML page with its
* content, so the page can be shown even when SilverStripe is not
* functioning correctly before publishing this page normally.
* @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
* @param string $toStage Place to copy to. Must be a stage name.
* @param boolean $createNewVersion Set this to true to create a new version number. By default, the existing version number will be copied over.
*/
function doPublish()
{
parent::doPublish();
// Run the page
$response = Director::test(Director::makeRelative($this->Link()));
$errorContent = $response->getBody();
// Check we have an assets base directory, creating if it we don't
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH, 02775);
}
// if the page is published in a language other than default language,
// write a specific language version of the HTML page
$filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Locale);
if ($fh = fopen($filePath, "w")) {
fwrite($fh, $errorContent);
fclose($fh);
} else {
$fileErrorText = sprintf(_t("ErrorPage.ERRORFILEPROBLEM", "Error opening file \"%s\" for writing. Please check file permissions."), $errorFile);
FormResponse::status_message($fileErrorText, 'bad');
FormResponse::respond();
return;
}
}
示例9: FieldHolder
/**
* @return String
*/
function FieldHolder()
{
Requirements::javascript(THIRDPARTY_DIR . "/greybox/AmiJS.js");
Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableListField.js');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/ComplexTableField.js");
Requirements::css(THIRDPARTY_DIR . "/greybox/greybox.css");
Requirements::css(SAPPHIRE_DIR . "/css/TableListField.css");
Requirements::css(SAPPHIRE_DIR . "/css/ComplexTableField.css");
// set caption if required
if ($this->popupCaption) {
$id = $this->id();
if (Director::is_ajax()) {
$js = <<<JS
\$('{$id}').GB_Caption = '{$this->popupCaption}';
JS;
FormResponse::add($js);
} else {
$js = <<<JS
Event.observe(window, 'load', function() { \$('{$id}').GB_Caption = '{$this->popupCaption}'; });
JS;
Requirements::customScript($js);
}
}
// compute sourceItems here instead of Items() to ensure that
// pagination and filters are respected on template accessors
$this->sourceItems();
return $this->renderWith($this->template);
}
示例10: delete
/**
* Custom delete implementation:
* Remove member from group rather than from the database
*/
function delete()
{
// Protect against CSRF on destructive action
$token = $this->getForm()->getSecurityToken();
// TODO Not sure how this is called, using $_REQUEST to be on the safe side
if (!$token->check($_REQUEST['SecurityID'])) {
return $this->httpError(400);
}
$groupID = Convert::raw2sql($_REQUEST['ctf']['ID']);
$memberID = Convert::raw2sql($_REQUEST['ctf']['childID']);
if (is_numeric($groupID) && is_numeric($memberID)) {
$member = DataObject::get_by_id('Member', $memberID);
$member->Groups()->remove($groupID);
} else {
user_error("MemberTableField::delete: Bad parameters: Group={$groupID}, Member={$memberID}", E_USER_ERROR);
}
return FormResponse::respond();
}
示例11: removememberfromgroup
public function removememberfromgroup()
{
$groupID = $this->urlParams['ID'];
$memberID = $this->urlParams['OtherID'];
if (is_numeric($groupID) && is_numeric($memberID)) {
$member = DataObject::get_by_id('Member', (int) $memberID);
if (!$member->canDelete()) {
return Security::permissionFailure($this);
}
$member->Groups()->remove((int) $groupID);
FormResponse::add("reloadMemberTableField();");
} else {
user_error("SecurityAdmin::removememberfromgroup: Bad parameters: Group={$groupID}, Member={$memberID}", E_USER_ERROR);
}
return FormResponse::respond();
}
示例12: saveInto
/**
* Saves the Dataobjects contained in the field
*/
function saveInto(DataObject $record) {
// CMS sometimes tries to set the value to one.
if(is_array($this->value)){
// Sort into proper array
$this->value = ArrayLib::invert($this->value);
$dataObjects = $this->sortData($this->value, $record->ID);
if(isset($dataObjects['new']) && $dataObjects['new']) {
$newFields = $this->sortData($dataObjects['new'], $record->ID);
}
$savedObj = $this->saveData($dataObjects, $this->editExisting);
if($savedObj && isset($newFields)) {
$savedObj = $this->saveData($newFields,false);
} else if(isset($newFields)) {
$savedObj = $this->saveData($newFields,false);
}
$items = $this->sourceItems();
FormResponse::update_dom_id($this->id(), $this->FieldHolder());
}
}
示例13: publish
/**
* When an error page is published, create a static HTML page with its
* content, so the page can be shown even when SilverStripe is not
* functioning correctly before publishing this page normally.
* @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
* @param string $toStage Place to copy to. Must be a stage name.
* @param boolean $createNewVersion Set this to true to create a new version number. By default, the existing version number will be copied over.
*/
function publish($fromStage, $toStage, $createNewVersion = false) {
$oldStage = Versioned::current_stage();
// Run the page
$response = Director::test(Director::makeRelative($this->Link()));
$errorContent = $response->getBody();
// Check we have an assets base directory, creating if it we don't
if(!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH, 02775);
}
// Path to the error file in the file store
$errorFile = ASSETS_PATH . "/error-$this->ErrorCode.html";
// Attempt to open the file, writing it if it doesn't exist
$fh = @fopen($errorFile, "w");
if($fh) {
fwrite($fh, $errorContent);
fclose($fh);
} else {
$fileErrorText = sprintf(
_t(
"ErrorPage.ERRORFILEPROBLEM",
"Error opening file \"%s\" for writing. Please check file permissions."
),
$errorFile
);
FormResponse::status_message($fileErrorText, 'bad');
FormResponse::respond();
return;
}
// Restore the version we're currently connected to.
Versioned::reading_stage($oldStage);
return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion);
}
示例14: createtranslation
/**
* Create a new translation from an existing item, switch to this language and reload the tree.
*/
function createtranslation($request)
{
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400);
}
$langCode = Convert::raw2sql($_REQUEST['newlang']);
$originalLangID = (int) $_REQUEST['ID'];
$record = $this->getRecord($originalLangID);
$this->Locale = $langCode;
Translatable::set_current_locale($langCode);
// Create a new record in the database - this is different
// to the usual "create page" pattern of storing the record
// in-memory until a "save" is performed by the user, mainly
// to simplify things a bit.
// @todo Allow in-memory creation of translations that don't persist in the database before the user requests it
$translatedRecord = $record->createTranslation($langCode);
$url = sprintf("%s/%d/?locale=%s", $this->Link('show'), $translatedRecord->ID, $langCode);
FormResponse::add(sprintf('window.location.href = "%s";', $url));
return FormResponse::respond();
}
示例15: doPublish
/**
* When an error page is published, create a static HTML page with its
* content, so the page can be shown even when SilverStripe is not
* functioning correctly before publishing this page normally.
* @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
* @param string $toStage Place to copy to. Must be a stage name.
* @param boolean $createNewVersion Set this to true to create a new version number. By default, the existing version number will be copied over.
*/
function doPublish()
{
parent::doPublish();
// Run the page (reset the theme, it might've been disabled by LeftAndMain::init())
$oldTheme = SSViewer::current_theme();
SSViewer::set_theme(SSViewer::current_custom_theme());
$response = Director::test(Director::makeRelative($this->Link()));
SSViewer::set_theme($oldTheme);
$errorContent = $response->getBody();
// Make the base tag dynamic.
// $errorContent = preg_replace('/<base[^>]+href="' . str_replace('/','\\/', Director::absoluteBaseURL()) . '"[^>]*>/i', '<base href="$BaseURL" />', $errorContent);
// Check we have an assets base directory, creating if it we don't
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH, 02775);
}
// if the page is published in a language other than default language,
// write a specific language version of the HTML page
$filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Locale);
if ($fh = fopen($filePath, "w")) {
fwrite($fh, $errorContent);
fclose($fh);
} else {
$fileErrorText = sprintf(_t("ErrorPage.ERRORFILEPROBLEM", "Error opening file \"%s\" for writing. Please check file permissions."), $errorFile);
FormResponse::status_message($fileErrorText, 'bad');
FormResponse::respond();
return;
}
}