- $name = $this->trimmed('name');
- $description = $this->trimmed('description');
- $source_url = $this->trimmed('source_url');
- $organization = $this->trimmed('organization');
- $homepage = $this->trimmed('application');
- $callback_url = $this->trimmed('callback_url');
- $this->type = $this->trimmed('type');
- $this->access_type = $this->trimmed('access_type');
-
- if (!is_null($name) && mb_strlen($name) > 255) {
- $this->showForm(_('Name is too long (max 255 chars).'));
- return;
- } else if (User_group::descriptionTooLong($description)) {
- $this->showForm(sprintf(
- _('description is too long (max %d chars).'),
- Oauth_application::maxDescription()));
- return;
- } elseif (!is_null($source_url)
- && (strlen($source_url) > 0)
+ $name = $this->trimmed('name');
+ $description = $this->trimmed('description');
+ $source_url = $this->trimmed('source_url');
+ $organization = $this->trimmed('organization');
+ $homepage = $this->trimmed('homepage');
+ $callback_url = $this->trimmed('callback_url');
+ $type = $this->arg('app_type');
+ $access_type = $this->arg('default_access_type');
+
+ if (empty($name)) {
+ // TRANS: Validation error shown when not providing a name in the "New application" form.
+ $this->clientError(_('Name is required.'));
+ } else if ($this->nameExists($name)) {
+ // TRANS: Validation error shown when providing a name for an application that already exists in the "New application" form.
+ $this->clientError(_('Name already in use. Try another one.'));
+ } elseif (mb_strlen($name) > 255) {
+ // TRANS: Validation error shown when providing too long a name in the "New application" form.
+ $this->clientError(_('Name is too long (maximum 255 characters).'));
+ } elseif (empty($description)) {
+ // TRANS: Validation error shown when not providing a description in the "New application" form.
+ $this->clientError(_('Description is required.'));
+ } elseif (Oauth_application::descriptionTooLong($description)) {
+ $this->clientError(sprintf(
+ // TRANS: Form validation error in New application form.
+ // TRANS: %d is the maximum number of characters for the description.
+ _m('Description is too long (maximum %d character).',
+ 'Description is too long (maximum %d characters).',
+ Oauth_application::maxDesc()),
+ Oauth_application::maxDesc()));
+ } elseif (empty($source_url)) {
+ // TRANS: Validation error shown when not providing a source URL in the "New application" form.
+ $this->clientError(_('Source URL is required.'));
+ } elseif ((strlen($source_url) > 0)