我添加了一个文本框以确保垃圾邮件发送者不会在我的留言簿上发帖。我用中文写了这个问题,所以它更难(我希望),但它似乎不起作用。如您所见,垃圾邮件发送者仍然可以发帖。它是如何完成的?
http://www.badmintontw.com/guestbook.php
谢谢你。
表格代码:
<script>
$(document).ready(function(){
$('#guestbook').submit( function(){
return valid_form();
});
});
function valid_form()
{
if ( $('#content').val() == ''){
alert('沒有留言');
return false;
}
if ($('#sum').val() != 12){
alert('請輸入正確的數字');
return false;
}
return true;
}
</script>
<h1>留言板</h1>
<p>對本網站有任何想法、問題,歡迎在此留言!</p>
<form name="guestbook" id="guestbook" action="guestbook_process.php" method="post">
<!--<input type = "hidden" name = "post_id" value = "<?php echo $id; ?>">-->
<textarea id="content" name = "content" placeholder="留言"></textarea>
<br />五加七等於多少? <input type="text" name="sum" id="sum">
<br /><input type="submit" name="submit" id="submit" value="送出">
</form>
guestbook_process.php 包含:
if(isset($_POST['submit'])){
if($_POST['content'] != ""){
$guestbook_insert_sql = "insert into badminton.guestbook(guestbook_ip, content, time) values (:guestbook_ip, :content, current_timestamp)";
$result = $db->prepare($guestbook_insert_sql);
$result->execute(array( ':guestbook_ip' => $_SERVER['REMOTE_ADDR'],
':content' => $_POST['content']));
header("Location: guestbook.php");
}else{
echo "沒有內容";
}
}