简体   繁体   English

如何使此CSS联系表单与javascript一起使用?

[英]How to make this CSS contact form working with javascript?

I want to insert this simple HTML/CSS contact form on my blog (blogger), the design is complete but since for this form to work (action='POST'), I do not know where to upload the php file. 我想在我的博客(博客)中插入这个简单的HTML / CSS联系人表单,设计已经完成,但是由于该表单可以正常工作(action ='POST'),因此我不知道将php文件上传到哪里。 I tried uploading the php code on my google drive, and also on dropbox, but how to make my form access that php file? 我尝试将php代码上传到我的Google驱动器以及Dropbox上,但是如何使我的表单访问该php文件? Every time I clicked on the submit button, blogger would give me an error msg. 每次我单击“提交”按钮时,博主都会给我一个错误消息。

Can I make this form work (ie the messages to be sent to my email id) by javascript/jquery or some other method? 我可以通过javascript / jquery或其他方法使此表单有效(即,要发送到我的电子邮件ID的消息)吗?

<div>
<form action="http://bandeutkalajanani.in/mailc.php" id="contact" method="post" name="contact">
<h1>You want to tell me something? Please go ahead. I would love to hear from you. </h1>
<input name="name" placeholder="Type in your name, please (e.g. - Amit Pattnaik)" required="" />
<input name="email" placeholder="Type in your email, please (e.g. - amit@email.com)" required="" type="email" />
<input name="website" placeholder="Type in your Website/Blog, if any (e.g. - http://www.amitpattnaik.com) (Optional though)" type="url" />
<textarea name="message" placeholder="Now tell me what's on your mind?" required=""></textarea>
<label>*What is 6+3 (in words)? (Anti-spam)</label>
<input name="human" placeholder="Type your answer in words" />
<button type="submit">Press to send me the message.</button> 
</form>
<h1><?php include "http://bandeutkalajanani.in/mailc.php"?></h1>
</div>

mail.php mail.php

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $url = $_POST['website'];
    $message = $_POST['message'];
    $from = 'From: GoodDayEveryDay'; 
    $to = 'amitg@gmail.com'; 
    $subject = 'Message from a Blog visitor';
    $human = $_POST['human'];

    $body = "From: $name\n E-Mail: $email\n Website: $url\n Message:\n 

$message";


if ($_POST['submit']) {
    if ($name != '' && $email != '') {
        if ($human == 'nine') {              
            if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!

</p>'; 
        } 
    } else if ($_POST['submit'] && $human != 'nine') {
        echo '<p>You answered the anti-spam question incorrectly!

</p>';
    }
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }
}
?>
#contact {
    width: 650px;
    height: 574px;
    margin: 15px auto 24px auto;
    padding: 24px;
    position: relative;
    background: #fff url(http://3.bp.blogspot.com/-uQYIg9e_IpU/VJaAtPsjRtI/AAAAAAAABzw/HOvtiBCjD_I/s1600/grunge_wall.png);
    border: 1px solid #ccc;
    border-radius: 3px;  
}

#contact::before, 
#contact::after {
    content: "";
    position: absolute;
    bottom: -3px;
    left: 2px;
    right: 2px;
    top: 0;
    z-index: -1;
    background: #fff;
    border: 1px solid #ccc;         
}

#contact::after {
    left: 4px;
    right: 4px;
    bottom: -5px;
    z-index: -2;
    box-shadow: 0 8px 8px -5px rgba(0,0,0,.3);
}

#contact h1 {
    position: relative;
    font: bold 1.1em/3.5em 'Segoe UI Light', 'Open Sans', sans-serif, Arial, Helvetica;

     color: #666;
    text-align: center;
    margin: 0 0 20px;
}

#contact h1::before,
#contact h1::after{
    content:'';
    position: absolute;
    border: 1px solid rgba(0,0,0,.15);
    top: 10px;
    bottom: 10px;
    left: 0;
    right: 0;
}

#contact h1::after{
    top: 0;
    bottom: 0;
    left: 10px;
    right: 10px;
}

::-webkit-input-placeholder {
   color: #bbb;
}

:-moz-placeholder {
   color: #bbb;
}                       

.placeholder{
    color: #bbb; /* polyfill */
}       

#contact input, textarea {
    margin: 5px 0;
    padding: 10px;
    width: 100%;
    *width: 518px; /* IE7 and below */
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 3px; 
}
#contact textarea {
    height:180px;
}
#contact input:focus{
        outline: 0;
        border-color: #aaa;
    box-shadow: 0 2px 1px rgba(0, 0, 0, .3) inset;
}       
#contact textarea:focus{
        outline: 0;
        border-color: #aaa;
    box-shadow: 0 2px 1px rgba(0, 0, 0, .3) inset;
}  
#contact button{
    margin: 20px 0 0 0;
    padding: 15px 8px;          
    width: 100%;
    cursor: pointer;
    border: 1px solid #2493FF;
    overflow: visible;
    display: inline-block;
    color: #fff;
    font: bold 1.4em 'Segoe UI Light', 'Open Sans', 'trebuchet MS',Arial, Helvetica;
    text-shadow: 0 -1px 0 rgba(0,0,0,.4);         
    background-color: #2493ff;
    background-image: linear-gradient(top, rgba(255,255,255,.5), rgba(255,255,255,0)); 
    transition: background-color .2s ease-out;
    border-radius: 3px;
    box-shadow: 0 2px 1px rgba(0, 0, 0, .3),
                0 1px 0 rgba(255, 255, 255, .5) inset;                               
}

#contact button:hover{
    background-color: #7cbfff;
        border-color: #7cbfff;
}

#contact button:active{
    position: relative;
    top: 3px;
    text-shadow: none;
    box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset;
}

Please find the html and CSS code in this fiddle: html css contact form 请在此小提琴中找到html和CSS代码: html css联系表

I do not know where to upload the php file. 我不知道在哪里上传php文件。

You need to upload it to web hosting that supports PHP and to which the URL specified in the action attribute of the form resolves. 您需要将其上传到支持PHP且表单的action属性中指定的URL可以解析到的Web托管。

I tried uploading the php code on my google drive, and also on dropbox, but how to make my form access that php file? 我尝试将php代码上传到我的Google驱动器以及Dropbox上,但是如何使我的表单访问该php文件?

Neither Google Drive not Dropbox provide web hosting which supports any kind of server side programming. Google Drive和Dropbox都不提供支持任何服务器端编程的网络托管。 You need to get a proper web host instead of using a cloud storage service that happens to allow public sharing of (static) files. 您需要获得适当的Web主机,而不是使用恰巧允许公共共享(静态)文件的云存储服务。

Can I make this form work (ie the messages to be sent to my email id) by javascript 我可以通过javascript使此表单正常工作(即要发送到我的电子邮件ID的邮件)吗?

Not in any practical way. 没有任何实际的方式。

In theory you could construct a mailto: URI and use JS to send the browser to it. 从理论上讲,您可以构造一个mailto: URI并使用JS将浏览器发送给它。 Depending on how the browser is configured, this might simply fail or it might open a pre-filled-in email in the user's email client which they could click send on. 根据浏览器的配置方式,这可能仅会失败,或者可能会在用户的电子邮件客户端中打开一个预填写的电子邮件,用户可以单击该电子邮件继续发送。 This is an unreliable and user-unfriendly approach that you shouldn't go anywhere near. 这是一种不可靠且用户不友好的方法,您不应靠近任何地方。

/jquery / jquery

jQuery is a JS library. jQuery是一个JS库。 You can't do anything with it that you can't do with JS already. 您无法使用它已经无法使用JS进行任何操作。

or some other method? 或其他方法?

You need a server side solution. 您需要服务器端解决方案。 Some companies will supply dedicated form to email gateways (ie a prewritten server side solution), but they tend to be inflexible. 一些公司将向电子邮件网关提供专用表格(即,预先编写的服务器端解决方案),但它们往往缺乏灵活性。

You'll need some sort of server set up to handly the post request, it wouldnt matter if you do a standard http post from a form or use javascript/jquery ajax. 您将需要某种服务器设置来处理发布请求,如果您从表单中执行标准的http发布或使用javascript / jquery ajax都没有关系。

If you cant use your own server try a email service or a iframed form service such as wooforms 如果您无法使用自己的服务器,请尝试使用电子邮件服务或iframed表单服务(例如wooforms)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM