データベースに永続化される前に、フォーム データに対して操作を実行できる必要があります。問題は、操作がリスクを伴う可能性があり、毎回ユーザーの同意が必要なことです。
Javascript 確認ウィンドウではなく、確認フォーム (何が起こっているかを説明する小さなメッセージ) を介してこれを行いたいと思います。
この機能を実現するにはどうすればよいですか?
フォームを処理するコントローラー アクション メソッドの例を次に示します。
<?php
public function indexAction(Request $request)
{
...
$form = $this->createFormBuilder($myEntity)
->add('someField', 'integer', array('required' => true))
// Lots and lots of fields
->getForm();
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
// CUSTOM VALIDATION HERE
// If invalid, must display a new confirmation form to ask user
// if it's alright to do a somewhat risky operation that would
// validate the form data.
// Else, persist the data.
$db = $this->getDoctrine()->getManager();
$db->persist($myEntity);
$db->flush();
return $this->redirect($this->generateUrl('my_path_to_success_page'));
}
}
return $this->render('MyBundle:Preferences:index.html.twig', array(
'form' => $form->createView(),
'errors' => $form->getErrors(),
));
}