phpcms v9表單嚮導中怎麼加入驗證碼
表單想到比較簡單,所以沒有加入驗證碼的功能。網上的類似教程又大多數不準確。所以親自測試了一下,發現下面的方法是可用的。希望對有需求的朋友們有所幫助。
1.首先是調用表單的頁面加入驗證碼。表單js調用模版默認的是 \phpcms\templates\default\formguide\show_js.html.
在該文件裏面找到這行代碼,大概在23行
<tr>
<th width="80">{if $info['star']} <font color="red">*</font>{/if} {$info['name']}
</th>
<td>{$info['form']} {$info['tips']}</td>
</tr>
{/loop}
在下面加入一行代碼。
<tr>
<td style="text-align:right;">驗證碼</td>
<td colspan="2">
<span title="點擊更換驗證碼" style=" cursor:pointer;">
<input type="text" id="code" name="code" size="8" class="input-text">
請輸入圖片中的驗證碼
</td>
</tr>
2.找到這個文件 \phpcms\modules\formguide\index.php
這個需要修改兩處
1)在第三行找到這行代碼。
defined('IN_PHPCMS') or exit('No permission resources.');
define('CACHE_MODEL_PATH',PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
然後在後面加入下面兩行代碼
$session_storage = 'session_'.pc_base::load_config('system','session_storage');
pc_base::load_sys_class($session_storage);
2)找到下面這行代碼
if (isset($_POST['dosubmit'])) {
$tablename = 'form_'.$r['tablename'];
$this->m_db->change_table($tablename);
然後在下面加入下面這段代碼
if(!empty($_SESSION['code'])) {
//判斷驗證碼
$code = isset($_POST['code']) && trim($_POST['code']) ? trim($_POST['code']) : showmessage(L('input_code'), HTTP_REFERER);
if ($_SESSION['code'] != strtolower($code)) {
showmessage(L('code_error'), HTTP_REFERER);
}
}