This way, there is no need to manually add the relevant code to the template.
See #2509
<p class="error" role="alert">{@$form->getErrorMessage()}</p>
{/if}
+{if $form->showsSuccessMessage()}
+ <p class="success">{@$form->getSuccessMessage()}</p>
+{/if}
+
{if $form->isAjax()}
<section id="{@$form->getId()}"{*
*}{if !$form->getClasses()|empty} class="{implode from=$form->getClasses() item='class' glue=' '}{$class}{/implode}"{/if}{*
<p class="error" role="alert">{@$form->getErrorMessage()}</p>
{/if}
+{if $form->showsSuccessMessage()}
+ <p class="success">{@$form->getSuccessMessage()}</p>
+{/if}
+
{if $form->isAjax()}
<section id="{@$form->getId()}"{*
*}{if !$form->getClasses()|empty} class="{implode from=$form->getClasses() item='class' glue=' '}{$class}{/implode}"{/if}{*
<p class="warning">{lang}wcf.acp.devtools.project.edit.warning{/lang}</p>
{/if}
-{if $success|isset}
- <p class="success">{lang}wcf.global.success.{$action}{/lang}</p>
-{/if}
-
{@$form->getHtml()}
{include file='footer'}
</nav>
</header>
-{if $success|isset}
- <p class="success">{lang}wcf.global.success.{$action}{/lang}</p>
-{/if}
-
{@$pipObject->getPip()->getAdditionalTemplateCode()}
{@$form->getHtml()}
</nav>
</header>
-{if $success|isset}
- <p class="success">{lang}wcf.global.success.{$action}{/lang}</p>
-{/if}
-
{@$form->getHtml()}
{include file='footer'}
</nav>
</header>
-{if $success|isset}
- <p class="success">{lang}wcf.global.success.{$action}{/lang}</p>
-{/if}
-
{@$form->getHtml()}
{include file='footer'}
$this->buildForm();
}
+
+ $this->form->showSuccessMessage(true);
}
/**
protected $requestData;
/**
- * TODO
+ * is `true` if global form error message will be shown if there are validation errors and
+ * is `false` otherwise
* @var boolean
*/
protected $showErrorMessage = true;
+ /**
+ * is `true` if global form success message will be shown and is `false` otherwise
+ * @var boolean
+ */
+ protected $showSuccessMessage = false;
+
+ /**
+ * global form success message
+ * @var null|string
+ */
+ protected $successMessage;
+
/**
* Cleans up the form document before the form document object is destroyed.
*/
public function errorMessage($languageItem = null, array $variables = []) {
if ($languageItem === null) {
if (!empty($variables)) {
- throw new \InvalidArgumentException("Cannot use variables when unsetting error element of form '{$this->getId()}'");
+ throw new \InvalidArgumentException("Cannot use variables when unsetting error message of form '{$this->getId()}'");
}
$this->errorMessage = null;
return $this->requestData;
}
+ /**
+ * @inheritDoc
+ */
+ public function getSuccessMessage() {
+ if ($this->successMessage === null) {
+ $suffix = 'edit';
+ if ($this->getFormMode() === IFormDocument::FORM_MODE_CREATE) {
+ $suffix = 'add';
+ }
+
+ $this->successMessage = WCF::getLanguage()->getDynamicVariable('wcf.global.success.' . $suffix);
+ }
+
+ return $this->successMessage;
+ }
+
/**
* @inheritDoc
*/
*/
public function showErrorMessage($showErrorMessage = true) {
$this->showErrorMessage = $showErrorMessage;
+
+ return $this;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function showSuccessMessage($showSuccessMessage = true) {
+ $this->showSuccessMessage = $showSuccessMessage;
return $this;
}
return $this->showErrorMessage;
}
+ /**
+ * @inheritDoc
+ */
+ public function showsSuccessMessage() {
+ return $this->showSuccessMessage;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function successMessage($languageItem = null, array $variables = []) {
+ if ($languageItem === null) {
+ if (!empty($variables)) {
+ throw new \InvalidArgumentException("Cannot use variables when unsetting success message of form '{$this->getId()}'");
+ }
+
+ $this->successMessage = null;
+ }
+ else {
+ if (!is_string($languageItem)) {
+ throw new \InvalidArgumentException("Given success message language item is no string, " . gettype($languageItem) . " given.");
+ }
+
+ $this->successMessage = WCF::getLanguage()->getDynamicVariable($languageItem, $variables);
+ }
+
+ return $this;
+ }
+
/**
* @inheritDoc
*/
* @throws \BadMethodCallException if this document has already been built
*/
public function build();
-
+
/**
* Sets the error message of this form using the given language item and returns this
* document. If `null` is passed, the error message is unset.
*
* @param null|string $languageItem language item containing the error message or `null` to unset error message
* @param array $variables additional variables used when resolving the language item
- *
* @return static this document
*
* @throws \InvalidArgumentException if the given form mode is invalid
*/
public function getRequestData($index = null);
+ /**
+ * Returns the success message for the whole form.
+ *
+ * By default, `wcf.global.form.add` or `wcf.global.form.edit` in the active user's language
+ * is returned depending on the current form mode.
+ *
+ * @return string
+ */
+ public function getSuccessMessage();
+
/**
* Returns `true` if the default button is added to the form during in the `build()` method
* and `false` otherwise.
*/
public function showErrorMessage($showErrorMessage = true);
+ /**
+ * Sets if the global form success message should be shown.
+ *
+ * @param boolean $showSuccessMessage
+ * @return static this document
+ */
+ public function showSuccessMessage($showSuccessMessage = true);
+
/**
* Returns `true` if the global form error message should be shown if the form has validation
* errors.
* @return boolean
*/
public function showsErrorMessage();
+
+ /**
+ * Returns `true` if the global form success message should be shown.
+ *
+ * By default, the global form error message is not shown.
+ *
+ * @return boolean
+ */
+ public function showsSuccessMessage();
+
+ /**
+ * Sets the success message of this form using the given language item and returns this
+ * document. If `null` is passed, the success message is unset.
+ *
+ * Unsetting the current success message causes `IFormDocument::getSuccessMessage()()` to
+ * return the default success message.
+ *
+ * @param null|string $languageItem language item containing the success message or `null` to unset error message
+ * @param array $variables additional variables used when resolving the language item
+ * @return static this document
+ *
+ * @throws \InvalidArgumentException if the given form mode is invalid
+ */
+ public function successMessage($languageItem = null, array $variables = []);
}