我正在用Symfony2为配镜师创建一个管理应用程序。当管理员将新客户添加到数据库时,我的控制器将检查客户名称是否重复。我想显示一个弹出对话框,询问用户是否要添加新客户。我该如何实施?我应该使用Ajax吗?这是我在这种情况下使用的控制器的示例代码:
public function nouveauAction(Request $request)
{
$form = $this->createFormBuilder()
->add('nom','text')
->add('tel','text', array('label' => 'Nº de téléphone', 'data' => '06'))
->add('email','email', array('label' => 'E-mail', 'required' => false))
->add('date','date', array('label' => 'Date d\'ajout', 'data' => new \DateTime()))
->add('ajouter','submit')
->getForm()
;
$form->handleRequest($request);
if ($form->isValid()){
$client = new Client();
$client->setNomClient($form["nom"]->getData());
$client->setTelClient($form["tel"]->getData());
$client->setEmailClient($form["email"]->getData());
$client->setDateEditionClient($form["date"]->getData());
//just for now (Later we'll retrieve the username from the session)
$em = $this->getDoctrine()->getEntityManager();
$user = (new Utilisateur)->rechercherParPseudo($em, 'admin');
$client->setIdUtilisateur($user);
$em = $this->getDoctrine()->getEntityManager();
if($client->existe($em))
{
//I need a popup message here : The customer you are trying to add already exists""
}
else
{
$request = $this->container->get('request');
if($client->existeNomDouble($em)) //If the customer name is duplicate
{
//I need a popup message here with Yes/No buttons...
}
else
{
//Writing to the database:
$em = $this->getDoctrine()->getEntityManager();
$client->ajouterClient($em);
//A notification to fade in here : "Customer successfully added"
}
}
}
return $this->render('ClientBundle:Client:nouveau.html.twig', array(
'formAjouter' => $form->createView(),
));
}
javascript大神给出的解决方案
尝试这个 :
控制器端:
$this->get('session')->getFlashBag()->add(
'notice',
'Customer Added!'
);
视图侧(树枝):
{% for flashMessage in app.session.flashbag.get('notice') %}
<div class="alert alert-success">
{{ flashMessage }}
</div>
{% endfor %}
在Wordpress插件中加载自定义JavaScript - javascript好的,这让我发疯了:我正在尝试构建一个简单的Wordpress插件,并且正在尝试确保js与php分开。我已经看过了法典和各种教程,但要么都是在做假设,要么是我只是个白痴,因为它不起作用...基本上,我最终希望通过ajax向自定义添加一些行添加帖子时使用表格,但首先我要让“ Hello World”在“添加帖子”页面上工作...当然,这很简单:这是myplug…
jQuery val函数在隐藏字段上不起作用? - javascript这是我的HTML代码:<div style='display:none;' id='allformid'> <div> <form action='#'> <input type='text' name='name' …
对Flask-Admin字段覆盖使用ACE语法荧光笔 - javascript在遵循以下有关覆盖flask-admin字段的提示之后,我试图使Ace语法荧光笔工作。https://flask-admin.readthedocs.io/en/latest/advanced/#wysiwig-text-fields这个想法是使SQLServer语法在wtforms文本区域上突出显示。此尝试不起作用,不确定额外的js中还包括什么?class…
我如何减少else语句[关闭] - javascriptClosed. This question is opinion-based。它当前不接受答案。 想改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。 6年前关闭。 我已经编写了一个函数来在三个链接之间放置“,”和“ and”我怎样才能减少if else语句。在javascript中,如果count不为零,我将得到count…
读取客户端上的提要时出现NotAllowedException - javascript嗨,我是GetStream的新手,仍然在学习。这是我正在使用的压缩版本。我有一个python后端,可在其中创建用户令牌:client = stream.connect(...) token = client.create_user_token(id) return token 然后,我将令牌传递给js前端,在该前端中该令牌用于检索该用户的feed活动。我正在…