[英]Form doesn't work inside fancybox
I have a form that works just fine when I try it out (with the correct address of course). 我有一个可以在尝试时正常工作的表格(当然带有正确的地址)。
When I use that for in my site, inside a fancybox it doesn't work. 当我在自己的网站中使用该功能时,它无法在fancybox中使用。 Nothing happens (no error in the console either).
什么也没发生(控制台中也没有错误)。
The relevant code is: 相关代码为:
<a class="fancybox" href="#inline1" id="link_consultar">
Consultar
</a>
<div style="display: none">
<div id="inline1">
Producto: {$product->
name|escape:'htmlall':'UTF-8'}
<br>
<br>
<form id="myForm" action="http://danielvi.com/send_mail.php" method="post">
Nombre:
<input type="text" name="firstname">
<br>
<br>
Consulta:
<br>
<textarea rows="4" cols="50">
</textarea>
<br>
<br>
<input type="submit" value="Enviar Consulta" />
</form>
</div>
</div>
The JS: JS:
$(document).ready(function() {
$('#myForm').submit(function(){
alert("submitted");
});
});
I have also tried: 我也尝试过:
$(document).ready(function() {
$("#myForm").on("submit", function(event){
alert("submitted");
});
});
I have included the form plugin like this: 我已经包括了这样的表单插件:
<script src="http://malsup.github.com/jquery.form.js"></script>
With no success, the end goal is to send form by AJAX, this is a simplified example to debug. 没有成功,最终目标是通过AJAX发送表单,这是调试的简化示例。
What I don't understand either is that even when I remove all js it wont direct me to the action page. 我也不明白的是,即使我删除所有js,也无法将我定向到操作页面。
You can see a live example here (When you click consulta). 您可以在此处看到一个实时示例(单击“咨询”时)。
The problem is shown on your live site. 该问题显示在您的实时站点上。 Upon examining the source code, you can see that you're adding a form within another form
查看源代码后,您可以看到您正在其他表单中添加表单
<form id="buy_block" action="http://danielvi.com/index.php?controller=cart" method="post">
[...]
<form id="myForm" action="http://danielvi.com/send_mail.php" method="post">
[...]
</form>
</form>
Which invalidates the second form you're working with. 这会使您正在使用的第二个表单无效。 That is why it's not doing anything.
这就是为什么它什么也不做。 Other than that, the code is valid.
除此之外,该代码是有效的。
在实际站点上 ,您似乎缺少#fancybox-content
的<form>
元素。
You've got the contact form inside form#buy_block which is invalid. 您在form#buy_block中有联系表格,该表格无效。 Try moving the whole
<div id="inline1">
outside of the <form id="buy_block
尝试将整个
<div id="inline1">
移动到<form id="buy_block
$("input[type='submit']").click(function(){
$.ajax: {
type : "POST",
cache : false,
url : "http://danielvi.com/send_mail.php",
success: function(data) {
$.fancybox({
'width': 400,
'height': 400,
'enableEscapeButton' : false,
'overlayShow' : true,
'overlayOpacity' : 0,
'hideOnOverlayClick' : false,
'content' : data
});
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.