## 留言板標簽
適用范圍:全站任意地方均可使用
標簽作用:用于用戶提交留言和調取留言記錄
#### 1、留言提交表單
~~~
<form action="{pboot:msgaction}" method="post">
聯系人:<input type="text" name="contacts" >
手機:<input type="text" name="mobile" >
內容:<input type="text" name="content" >
驗證碼:<input type="text" name="checkcode" >
<img title="點擊刷新" src="{pboot:checkcode}" onclick="this.src='{pboot:checkcode}?'+Math.round(Math.random()*10);" />
<button type="submit">提交</button></form>
~~~
表單提交方式為post,表單中提交的字段名稱需要與后臺自定義表單中添加的字段一致,否則會導致提交失敗。
需要更多字段時請在后臺自定義表單中新增留言表單字段,然后再在前臺新增form字段.
標簽說明:
{pboot:msgaction} 為留言表單接收地址
{pboot:checkcode} 為驗證碼圖片地址
### pbootcms使用Ajax無刷新提交留言及表單
1.表單驗證
~~~
<form?onsubmit="return?submsg(this);">
????聯系人<input?type="text"?name="contacts"?required?id="contacts">
????手 機<input?type="text"?name="mobile"?required?id="mobile">
????內 容<textarea?name="content"?id="content"></textarea>
????驗證碼<input?type="text"?name="checkcode"?required?id="checkcode">
????<img?title="點擊刷新"?src="{pboot:checkcode}"?onclick="this.src='{pboot:checkcode}?'+Math.round(Math.random()*10);"?/>
????<button?type="submit">提交留言</button>
</form>
~~~
2、Ajax提交
~~~
<script>
//ajax提交留言,由于涉及到提交地址標簽的解析,JS需要放在html文件中
function?submsg(obj){
??var?url='{pboot:msgaction}';?//如果是自定義表單則使用地址{pboot:form?fcode=*}
??var?contacts=$(obj).find("#contacts").val();
??var?mobile=$(obj).find("#mobile").val();
??var?content=$(obj).find("#content").val();
??var?checkcode=$(obj).find("#checkcode").val();
//此處加個判斷,避免碰到刷留言
??if?(!$('[name="contacts"]').val())?{alert('姓名不能為空');returnfalse;???}
// 判斷在要寫入數組前,(我也是小白一個 判斷寫的不好,還請大佬們指教)
??$.ajax({
????type:?'POST',
????url:?url,
????dataType:?'json',
????data:?{
????????contacts:?contacts,
????????mobile:?mobile,
????????content:?content,
????????checkcode:?checkcode
????},
????success:?function?(response,?status)?{
??????if(response.code){
?????????alert("謝謝您的反饋,我們會盡快聯系您!");
?????????$(obj)[0].reset();?
??????}else{
?????????alert(response.data);
??????}
????},
????error:function(xhr,status,error){
??????alert('返回數據異常!');
????}
??});
??return?false;
}
</script>
~~~
#### 2、留言記錄列表
~~~
{pboot:message num=*}
<p>[message:contacts]</p>
<p>[message:content]</p>
{/pboot:message}
~~~
調取的留言記錄默認執行分頁,使用內容列表的分頁代碼即可.
內容隱私,使用截取功能: \[message:mobile substr=1,3\]****\[message:mobile substr=8\] 輸出效果:187****6563
控制參數:
num=\* 數量,非必填,為調取的留言分頁大小
page=\* 是否分頁1或0,非必填,用于關閉分頁
lg=\* 調取指定語言留言,非必填,設置all則所有語言,不添加該參數則默認為當前語言(V1.3.7+)
#### 3、留言記錄列表可用標簽
|[message:n]|序號從0開始
|---|---|
|[message:i]序號從1開始
|[message:contacts]|聯系人|
|[message:mobile]|手機|
|[message:content]|內容|
|[message:recontent]|回復內容|
|[message:ip]|用戶IP|
|[message:os]|用戶操作系統|
|[message:bs]|用戶瀏覽器|
|[message:askdate]|留言時間|
|[message:replydate]|回復時間|
|[message:*]|自定義的其它字段|