diff --git a/app/controllers/registration.php b/app/controllers/registration.php index edb6b42d0ed31decc5a84d9194ebd9089552192e..de86683677841a51e85d715023e21c64b138a90c 100644 --- a/app/controllers/registration.php +++ b/app/controllers/registration.php @@ -1,4 +1,7 @@ <?php + +use Studip\Forms\Form; + class RegistrationController extends AuthenticatedController { protected $allow_nobody = true; @@ -14,7 +17,7 @@ class RegistrationController extends AuthenticatedController { $new_user = new User(); - $this->registrationform = \Studip\Forms\Form::fromSORM( + $this->registrationform = Form::fromSORM( $new_user, [ 'legend' => _('Herzlich willkommen!'), @@ -108,7 +111,7 @@ class RegistrationController extends AuthenticatedController $this->registrationform->setCancelButtonName(URLHelper::getURL('index.php?cancel_login=1')); $this->registrationform->addStoreCallback( - function ($form) { + function (Form $form) { $new_user = $form->getLastPart()->getContextObject(); $GLOBALS['sess']->regenerate_session_id(['auth']); diff --git a/lib/classes/forms/Form.php b/lib/classes/forms/Form.php index fb3ff10b143da2f73c3f91e763820d150d01d2d8..5e27895455fe6f4d93ba7dd7d91a64ae9d7fd434 100644 --- a/lib/classes/forms/Form.php +++ b/lib/classes/forms/Form.php @@ -318,6 +318,7 @@ class Form extends Part } } } + header('Content-Type: application/json'); echo json_encode($output); page_close(); die(); diff --git a/resources/assets/javascripts/bootstrap/forms.js b/resources/assets/javascripts/bootstrap/forms.js index dbd4613f6ef351dbcc41ebe587df65a4a1a1f0cd..e379d422f1f08323ace4057f11db5d1a19657005 100644 --- a/resources/assets/javascripts/bootstrap/forms.js +++ b/resources/assets/javascripts/bootstrap/forms.js @@ -323,11 +323,10 @@ STUDIP.ready(function () { let v = this; this.STUDIPFORM_VALIDATIONNOTES = []; - let validation_promise = new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { let validated = v.$el.checkValidity(); $(v.$el).find('input, select, textarea').each(function () { - let name = $(this).attr('name'); if (!this.validity.valid) { let note = { name: this.name, @@ -362,35 +361,30 @@ STUDIP.ready(function () { v.STUDIPFORM_VALIDATIONNOTES.push(note); } }); - if (v.STUDIPFORM_SERVERVALIDATION) { + if (v.STUDIPFORM_SERVERVALIDATION) { let params = v.getFormValues(); + if (v.STUDIPFORM_AUTOSAVEURL) { + params.STUDIPFORM_AUTOSTORE = 1; + } params.STUDIPFORM_SERVERVALIDATION = 1; - $.ajax({ - url: v.STUDIPFORM_VALIDATION_URL, - data: params, - type: 'post', - dataType: 'json', - success(output) { - for (let i in output) { - let note = { - name: output[i].name, - label: output[i].label, - description: output[i].error, - describedby: null - }; - v.STUDIPFORM_VALIDATIONNOTES.push(note); - } - validated = v.STUDIPFORM_VALIDATIONNOTES.length < 1; - resolve(validated); + $.post(v.STUDIPFORM_VALIDATION_URL, params).done((output) => { + for (let i in output) { + v.STUDIPFORM_VALIDATIONNOTES.push({ + name: output[i].name, + label: output[i].label, + description: output[i].error, + describedby: null + }); } + validated = v.STUDIPFORM_VALIDATIONNOTES.length < 1; + resolve(validated); }); } else { resolve(validated); } }); - return validation_promise; }, setInputs(inputs) { for (const [key, value] of Object.entries(inputs)) {