我正在使用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 …Run Code Online (Sandbox Code Playgroud) 我有一个清除列表的按钮,单击此按钮会显示一个要求验证的对话框(是/否).我想要的是清除列表后禁用"清除"按钮(单击是).这是我的代码:
$('#clearBtn').click(function() {
$('#alert5').show();
$('#bg').show();
$('#Yes').click(function(){
$('.list1').empty();
$('#clearBtn').disable(true);
$('#clearBtn').click(function(e){
e.preventDefault();
});
$(".alert").fadeOut(250);
$(".alertbg").fadeOut(250);
});
});
Run Code Online (Sandbox Code Playgroud)
preventDefault()函数似乎不起作用.