[英]How to put IF condition for input field in a contact form (PHP, CODEIGNITER)
PHP控制器:
$this->form_validation->set_rules('phone', $this->language->get_text('phone', 'global'), 'max_length[0]');
我需要為上面的代碼添加IF條件以返回此代碼:
if (The_Above_Line_Code is NOT empty)
{
$this->output->set_status_header(400);
exit;
}
因此,如果輸入字段不包含字符,則可以,聯系表單可以正常工作,但是如果包含字符,則應返回空白頁(set_status_header(400))。
PS:這是一種以聯系方式打擊垃圾郵件的方法。
$this->form_validation->set_rules('phone', $this->language->get_text('phone', 'global'), 'max_length[0]|numeric');
如果不是數字,則表單驗證失敗。 我看不到400人用餐的邏輯。
更新
更好地理解您的推理之后,您可以執行以下操作:
if (!empty($this->input->post('phone'))) {
show_404(); // sets header + exits
}
您甚至可以使用show_404()
(CI函數)作為記錄錯誤的方式: show_404('bot detected', true);
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.