HTML订阅表单

时间:2016-02-21 11:24:09

标签: php html

我编写了代码来获取我的用户的订阅,该用户将在表单框中编写他们的电子邮件ID,但没有获取代码。

我的HTML订阅表格的主要代码是

$path = "F:\Masterarbeit\Daten"
$search = "Das ist ein Test"

# loop through all files
foreach ($file in Get-ChildItem $path -Filter *.sql -Recurse) {
    # get all lines from the current file containing the test string 
    $test = Get-Content $file.FullName | Select-String $search
    # are there any?
    if ($test) {
        # then skip this one
        continue
    }
    # otherwise print the file name
    $file
}

我已经订阅了subscribe.php并编写了代码 但我没有在我想要的电子邮件ID上收到订阅电子邮件该怎么办?

<form action="subscribe.php" class="subscribe" id="subscribe">
  <input type="email" placeholder="Enter your email" class="email form_item requiredField" name="subscribe_email" />
  <input type="submit" class='form_submit' value="subscribe" />
  <div id="form_results"></div>
</form> 

2 个答案:

答案 0 :(得分:0)

您缺少代码中的ajax脚本:应该是这样的

首先包括一个jquery库

$("#expList ol li")

然后是ajax代码

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>

然后是您的HTML,但我已在您的电子邮件文本框中添加了一个ID以进行验证

<script>
$(function(){
$(document).on("click", ".form_submit", function(e) {
e.preventDefault();

//validate 
var emailz = $("#email").val();

var emailp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

if (email=='')
{
alert("Please enter your email address");

}
else if (!emailp.test(emailz))
{
alert("Please enter a valid email");

}
else {              
    //Built a url to send
    var info = $("#subscribe").serialize();

    $.ajax({

        type: "POST",
        url: "subscribe.php",
        data: info,
        success: function(result){          
            //$("#form")[0].reset();
              $('#form_results').html(html); 
        }
    });     
    e.preventDefault(); 
    }
});

});
</script>

答案 1 :(得分:0)

根据提交表单的方法,您可能需要稍微更改html。如果您使用的是传统的提交按钮,那么您需要将方法(如method ='post')添加到表单中,但如果您使用的是ajax,那么我建议您将提交按钮更改为{{1}并为其分配事件监听器(事件监听器执行ajax请求的地方)

button