Skip to content

Commit

Permalink
Display some actions after a form is submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienClairembault committed Dec 26, 2024
1 parent 5ed9f50 commit ac53717
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions js/modules/Forms/RendererController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* ---------------------------------------------------------------------
*/

/* global glpi_toast_info */
/* global glpi_toast_info, glpi_toast_error */

/**
* Client code to handle users actions on the form_renderer template
Expand Down Expand Up @@ -143,7 +143,9 @@ export class GlpiFormRendererController
.addClass("d-none");

} catch {
// Failure (TODO)
glpi_toast_error(
__("Failed to submit form, please contact your administrator.")
);
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/Glpi/Controller/Form/RendererController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@

final class RendererController extends AbstractController
{
private string $interface;

public function __construct() {
$this->interface = Session::getCurrentInterface();
}

#[SecurityStrategy(Firewall::STRATEGY_NO_CHECK)] // Some forms can be accessed anonymously
#[Route(
"/Form/Render/{id}",
Expand All @@ -63,11 +69,30 @@ public function __invoke(Request $request): Response
$form = $this->loadTargetForm($request);
$this->checkFormAccessPolicies($form, $request);

$my_tickets_criteria = [
"criteria" => [
[
"field" => 12, // Status
"searchtype" => "equals",
"value" => "notold", // Not solved
],
],
];
if ($this->interface == 'central') {
$my_tickets_criteria["criteria"][] = [
"link" => "AND",
"field" => 4, // Requester
"searchtype" => "equals",
"value" => 'myself',
];
}

return $this->render('pages/form_renderer.html.twig', [
'title' => $form->fields['name'],
'menu' => ['admin', Form::getType()],
'form' => $form,
'unauthenticated_user' => !Session::isAuthenticated(),
'my_tickets_url_param' => http_build_query($my_tickets_criteria),

// Direct access token must be included in the form data as it will
// be checked in the submit answers controller.
Expand Down
8 changes: 8 additions & 0 deletions templates/pages/form_renderer.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@
<p class="empty-subtitle text-secondary">
{{ __("Your form has been submitted successfully.") }}
</p>
<div class="mt-3 d-flex">
<a class="btn btn-outline-secondary me-2" href="{{ path('/ServiceCatalog') }}">
{{ __("Go back to service catalog") }}
</a>
<a class="btn btn-outline-secondary" href="{{ path('/front/ticket.php?' ~ my_tickets_url_param) }}">
{{ __("See my tickets") }}
</a>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit ac53717

Please sign in to comment.