The form thought relatively simple, so did not add the verification code function. Similar tutorials on the web are mostly inaccurate. So personally tested, found the following method is available. Hope to have the help of friends who need.
1 The first page that invokes the form joins the verification code. Form JS Call Template The default is \phpcms\templates\default\formguide\show_js.html.
Find this line of code in this file, about 23 lines
1 2 3 4 5 6 |
<tr> <th width= "80" >{ if $info[ ‘star‘ ]} <font color= "red" >*</font>{/ if } {$info[ ‘name‘ ]} </th> <td>{$info[ ‘form‘ ]} {$info[ ‘tips‘ ]}</td> </tr> {/loop} |
Add a line of code below.
1 |
<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" >{form::checkcode( ‘code_img‘ , ‘4‘ , ‘14‘ , 84 , 24 )}</span>请输入图片中的验证码</td></tr> |
2 found this file \phpcms\modules\formguide\index.php
This needs to be modified in two places.
1) Find this line of code on the third line.
0 S |
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); |
Then add the following two lines of code to the back
0 S |
$session_storage = ‘session_‘ .pc_base::load_config( ‘system‘ , ‘session_storage‘ ); pc_base::load_sys_class($session_storage); |
2) Find the following line of code
1 2 3 |
if (isset($_POST[ ‘dosubmit‘ ])) { $tablename = ‘form_‘ .$r[ ‘tablename‘ ]; $ this ->m_db->change_table($tablename); |
Then add the following code below
1 2 3 4 5 6 7 |
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); } } |
OK, refresh your form page, the random code has come out.