diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/classes/StudipController.php | 29 | ||||
| -rw-r--r-- | lib/classes/forms/Form.php | 12 |
2 files changed, 29 insertions, 12 deletions
diff --git a/lib/classes/StudipController.php b/lib/classes/StudipController.php index 3ac80e8..00e086e 100644 --- a/lib/classes/StudipController.php +++ b/lib/classes/StudipController.php @@ -14,6 +14,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Csv; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use Studip\WizardPart; +use Studip\Forms\Form; /** * @property StudipResponse $response @@ -608,14 +609,26 @@ abstract class StudipController extends Trails\Controller */ public function render_wizard(array $steps, bool $showAllSteps = true): void { - $this->render_vue_app( - Studip\VueApp::create('StudipWizard') - ->withProps([ - 'steps' => $steps, - 'showAllSteps' => $showAllSteps - ]) - ->withStore('wizardStore', 'useWizardStore') - ); + if (Request::get('step_id', null) !== null && Request::isXhr()) { + $step = array_find($steps, fn ($entry) => $entry->getId() === Request::get('step_id')); + + if ($step && $step->getType() === Form::class) { + $validated = $step->getContent()->validate(true); + $this->render_json($validated); + } else { + $this->set_status(404); + $this->render_nothing(); + } + + } else { + $this->render_vue_app( + Studip\VueApp::create('StudipWizard') + ->withProps([ + 'steps' => $steps, + 'showAllSteps' => $showAllSteps + ]) + ); + } } diff --git a/lib/classes/forms/Form.php b/lib/classes/forms/Form.php index f34b68d..58ff72d 100644 --- a/lib/classes/forms/Form.php +++ b/lib/classes/forms/Form.php @@ -314,7 +314,7 @@ class Form extends Part return $this; } - public function validate() + public function validate(bool $return = false) { if (\Request::isPost() && \Request::submitted('STUDIPFORM_SERVERVALIDATION')) { //verify the user input: @@ -333,10 +333,14 @@ class Form extends Part } } } - header('Content-Type: application/json'); - echo json_encode($output); sess()->save(); - die(); + if ($return) { + return $output; + } else { + header('Content-Type: application/json'); + echo json_encode($output); + die(); + } } return $this; } |
