A lightweight solution is to actually show your form twice:
First, the user fills all fields. Then we recognise that it has not been confirmed already so we re-render it. This time the javascript immediately presents the confirmation dialog.
To this end we add a hidden field confirmed
to the form and a parameter to the twig rendering:
$builder = $this->createFormBuilder(...);
$builder->add('confirmed', HiddenType::class, ['mapped' => false]);
$form = $builder->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if($form->get('confirmed')->getData() != true) {
// re-render with confirmation flag set
return $this->render('default/form.html.twig', [
'form' => $form->createView(),
'confirm' => true]);
}
} else {
return $this->render('default/form.html.twig', [
'form' => $form->createView(),
'confirm' => false]);
}
And in your template to add a javascript like:
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
<script>
$(document).ready(function () {
var c = confirm('Really sure?');
if(c) {
$('#form_confirmed').val(true);
$('form')[0].submit();
}
});
</script>