【发布时间】:2016-09-12 00:21:04
【问题描述】:
Symfony3 Forms:我已经成功地构建和呈现了如下所示的表单:
<form action="/member/john/actions" method="post" name="form">
<input type="submit" value="Block John" name="block">
<input type="submit" value="Remove from my friends" name="remove">
<input type="hidden" value="LeiajURspTa9c8JEUYtvepki0b_CdL9dMWqEZxOYvfk" name="form[_token]" id="form__token">
</form>
当我点击按钮 "Block John" 或 "Remove from my friends" 时,控制器会将其路由到所需位置 (member_friend_actions) 并且它能够显示 调试转储值 em> 连同"Submitted!" 文字,在死之前。
我的路由“member_friend_actions”的控制器设置如下:
/**
* A common post location to catch all operations like add/remove/cancel/block friends
*
* @Route("/{username}/actions", name="member_friend_actions")
* @Method("POST")
*/
public function allActionsFriendAction(Request $request, User $friend)
{
$form = $this->createAllActionsFriendForm($friend);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//$clicked = $form->getData();
$clicked = $form->getClickedButton()
\Doctrine\Common\Util\Debug::dump($clicked);
die("Submitted!");
}
return $this->redirectToRoute('member_profile', array("username" => $friend->getUsername()));
}
我想知道点击了哪个按钮将它带到这里(在此处阻止或删除;但在其他地方可以有更多按钮)。我尝试使用这些方法:
$form->getData() => 给出 array(0) { } 和
$form->getClickedButton() => 给出 NULL,所以没有帮助。
如何做到这一点?
【问题讨论】:
-
你好任。如果我的回答确实“解决”了问题,也请单击我的回答旁边的复选标记,将其标记为正确的。谢谢!
标签: php controller symfony symfony-forms