联系人表单-Html和Javascript仅包含在Html中(tumblr)
我试图在我的tumblr博客中包含一个联系人表单(我将其用作公文包)。关键是我已经有了表单的html和css,但是我不能让部分工作。主要是因为我不能引用.js文件。我的意思是,我需要将.js文件中的代码包含在html中,这样它才能正常工作 也许有别的方法可以让这更容易,但我无论如何也找不到办法 以下是html格式:联系人表单-Html和Javascript仅包含在Html中(tumblr),javascript,html,css,forms,tumblr,Javascript,Html,Css,Forms,Tumblr,我试图在我的tumblr博客中包含一个联系人表单(我将其用作公文包)。关键是我已经有了表单的html和css,但是我不能让部分工作。主要是因为我不能引用.js文件。我的意思是,我需要将.js文件中的代码包含在html中,这样它才能正常工作 也许有别的方法可以让这更容易,但我无论如何也找不到办法 以下是html格式: <form id="c_form" name="contact"> <div> <label>
<form id="c_form" name="contact">
<div>
<label>
<p>Name</p>
<input name="nombre" id="c_name" type="text" class="c_input" placeholder="..."/>
</label>
<br/>
<label>
<p>Email:</p>
<input name="email" id="c_mail" type="text" class="c_input" placeholder="..."/>
</label>
</div>
<label>
<p>Content:</p>
<textarea name="mensaje" id="c_msg" placeholder="..."></textarea>
</label>
<div id="c_btns">
<input name="send" onclick="cargaSendMail()" type="button" value="Enviar" class="btn-b" id="c_enviar"></input>
</div>
</form>
如果我是对的,我应该添加一个:
<script type='text/javascript' ......(code)></script>
这就是表单工作的原因,但我不知道代码应该是什么
也许我错过了smth,但这是我第一次使用js,我刚刚使用html和css
提前谢谢 您可以注册并使用
查看通过JSON提交的文件。我在我的网站上使用这种方法
jQuery(函数($)
{
$(“#联系表格”)。提交(函数()
{
var email=$(“#email”).val();//获取电子邮件字段值
var name=$(“#name”).val();//获取名称字段值
var msg=$(“#msg”).val();//获取消息字段值
$.ajax(
{
类型:“POST”,
url:“https://mandrillapp.com/api/1.0/messages/send.json",
数据:{
“键”:“sVRLFidC1A7K56TuUkyUQg”,
“消息”:{
“来自电子邮件”:电子邮件,
“from_name”:名称,
“标题”:{
“回复”:电子邮件
},
'主题':'网站联系表格提交',
“文本”:msg,
“致”:[
{
“电子邮件”:riyadh@bscheme.com',
“姓名”:“利雅得努尔”,
'type':'to'
}]
}
}
})
.完成(功能(响应){
警报('您的邮件已发送。谢谢!');//显示成功邮件
$(“#name”).val(“”);//成功提交后重置字段
$(“#email”).val(“”);//成功提交后重置字段
$(“#msg”).val(“”);//成功提交后重置字段
})
.失败(功能(响应){
警报(“发送消息时出错”);
});
返回false;//防止页面刷新
});
});代码>
联系我们
名称
电子邮件
消息
发送消息
有几种方法可以做到这一点。首先,你们有表单处理器吗?如果没有,我建议。他们有一个免费帐户,您的表格可以发送到该帐户。它会处理输入,并将结果通过电子邮件免费发送给您
为您的javascript尝试以下操作:
function cargaSendMail(){
var nombre = document.forms["contact"]["nombre"].value;
var email = document.forms["contact"]["email"].value;
var mensaje = document.forms["contact"]["mensaje"].value;
// The following "ifs" make sure that the user has filled out all fields.
if (nombre == null || nombre == ""){
alert("Please enter your name"); // Alert the user if he has not entered his name.
return false; // Stop running this function if the user has not entered his name.
}
if (email == null || email == ""){
alert("Please enter your email");
return false;
}
if (mensaje == null || mensaje == ""){
alert("Please enter your mensaje");
return false;
}
document.forms["contact"].submit();
/* If all fields are filled out, they code will not "return false"
and will submit the form. */
}
请记住,除非您指定表单“action”属性,否则此JS将不会执行任何操作。您在表单的“action”属性中输入的url将是处理表单信息的位置。如果您使用allforms,它们将为您提供url和其他操作说明。如果我需要更详细的解释,请告诉我。希望这有帮助 在哪里定义了cargaSendMail()
函数?这个主意不错,但是让任何人(ab)免费使用你的mandril凭证似乎很危险。文档中提到了它,但是如果你想要一个完整的JS解决方案,你没有太多的选择…它工作得非常好!谢谢你,布迪。也谢谢大家!欢迎@MazrimTaim!如果答案对你有用,请接受。
function cargaSendMail(){
var nombre = document.forms["contact"]["nombre"].value;
var email = document.forms["contact"]["email"].value;
var mensaje = document.forms["contact"]["mensaje"].value;
// The following "ifs" make sure that the user has filled out all fields.
if (nombre == null || nombre == ""){
alert("Please enter your name"); // Alert the user if he has not entered his name.
return false; // Stop running this function if the user has not entered his name.
}
if (email == null || email == ""){
alert("Please enter your email");
return false;
}
if (mensaje == null || mensaje == ""){
alert("Please enter your mensaje");
return false;
}
document.forms["contact"].submit();
/* If all fields are filled out, they code will not "return false"
and will submit the form. */
}