好吧,我实际上已经通过一个非常简单的解决方案取得了很大的成功。
创建一个 CSS 类:
.magic /* Call it whatever you want
{
display: none;
}
在您的表单中插入类似这样的内容:
<form method="post" action="">
<p>
<label>Name</label>
<input type="text" name="name">
<p>
<!-- and the magic -->
<p class="magic">
<input type="text" name="email"> <!-- spam bots LOVES 'email' fields ;) -->
</p>
<!-- /end magic -->
<p>
<label>Real E-mail input field</label>
<input type="text" name="some_email">
</p>
</form>
在您的控制器中,您可以执行以下操作:
...
public function create_post()
{
$this->form_validation... // If you use form validation
[...]
// If all regular validations are true, do the last bit
if( $this->input->post('email') == "" ) //If something is in the 'email' field, it has propbably been filled by a bot, because regular users can't see the field.
{
$this->your_model->insert_the_post($data);
}
// otherwise, pretend like nothing.
}
您的用户将永远不会看到这一点 - 这让我多年来一直没有垃圾邮件。简单 - 但有效。