v1.6
表单标签
内链导航
属性 | 值 | 描述 |
---|---|---|
name | 默认是ad,定义val | 一般定义val来使用,标签统一使用方法 |
id | 表单ID | 指定所需要使用的表单ID |
动态提交表单应用:例子一
{oy:aform id="1" name="val"}
<form id="form1" class="form-wrapper">
<input type="text" name="name" class="form-control" placeholder="你的姓名">
<input type="text" name="email" class="form-control" placeholder="邮件地址">
<input type="text" name="phone" class="form-control" placeholder="电话">
<!-- <input type="text" class="form-control" placeholder="项目"> -->
<textarea name="message" class="form-control" placeholder="你的留言内容"></textarea>
<input type="hidden" name="fname" value="{$val.fname}" />
<input type="hidden" id="ctoken" name="token" value="{$val.token}" />
<input type="hidden" name="ysource" value="{$view_url}" placeholder="访问网址"/>
<button type="button" id="send" class="btn btn-primary">提交 <i class="fa fa-envelope-open-o"></i></button>
</form>
{/oy:aform}
<script src="http://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
<script>
$(function(){
$('#send').click(function(){
var d = {};
var t = $('#form1').serializeArray();
$.each(t, function() {
d[this.name] = this.value;
});
var ctoken = $("#ctoken").val()
var sendData = d
$.ajax({
type: "POST",
headers: {
Token: ctoken
},
url: "/api/form/enroll",
data: sendData,
dataType: "json",
success: function(res){
console.log('data:', res)
if(res.errorCode != 20000){
alert('提交失败');
return false;
}
alert('提交成功');
}
});
});
});
</script>
动态提交表单,相关的参数应用
{oy:aform id="1" name="val"}
<form>
<div class="form-group">
<label for="exampleInputEmail1">姓名</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<small id="emailHelp" class="form-text text-muted">请输入您的姓名</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">电话</label>
<input type="text" class="form-control" id="exampleInputPassword1">
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">用户信息声明</label>
</div>
<input type="hidden" id="ctoken" name="token" value="{$val.token}" />
<!-- <button type="submit" class="btn btn-primary">提交</button> -->
<button type="button" id="send" class="btn btn-primary">提交</button>
</form>
{/oy:aform}
动态提交表单
<script>
$(function(){
$('#send').click(function(){
var sendData = {
name:'小颖',
tel:'13811111111',
}
var ctoken = $("#ctoken").val()
$.ajax({
type: "POST",
headers: {
Token: ctoken
},
url: "{$val.ajaxpath}",
data: sendData,
dataType: "json",
success: function(data){
console.log('data:', data)
// $('#resText').empty(); //清空resText里面的所有内容
// var html = '';
// $.each(data, function(commentIndex, comment){
//
html += '<div class="comment"><h6>' + comment['username']
//
+ ':</h6><p class="para"' + comment['content']
//
+ '</p></div>';
// });
// $('#resText').html(html);
}
});
});
});
</script>
评论提交
<div class="blog-box clearfix">
<div class="custom-title">
<h4>对“{$uanzlu.title}”发表评论</h4>
</div><!-- end about -->
<div class="contact_form comment-form">
{oy:aform id="1" name="val"}
<form id="form1" class="row">
<div class="col-md-4 col-sm-12">
<label>昵称 <span class="required">*</span></label>
<input name="nickname" type="text" class="form-control" placeholder="">
</div>
<div class="col-md-12 col-sm-12">
<label>留言内容 <span class="required">*</span></label>
<textarea name="content" class="form-control" placeholder=""></textarea>
</div>
<div class="col-md-12 col-sm-12">
<input type="hidden" name="form_id" value="2" />
<input type="hidden" name="aid" value="{$uanzlu.aid}" />
<input type="hidden" name="fname" value="{$val.fname}" />
<input type="hidden" id="ctoken" name="token" value="{$val.token}" />
<input id="send" type="button" value="发表" class="btn btn-primary" />
</div>
</form>
{/oy:aform}
</div><!-- end commentform -->
</div><!-- end postpager -->
<script>
$(function(){
$('#send').click(function(){
var d = {};
var t = $('#form1').serializeArray();
$.each(t, function() {
d[this.name] = this.value;
});
var ctoken = $("#ctoken").val()
var sendData = d
$.ajax({
type: "POST",
headers: {
Token: ctoken
},
url: "/api/form/message",
data: sendData,
dataType: "json",
success: function(res){
console.log('data:', res)
if(res.errorCode != 20000){
alert('提交失败');
return false;
}
alert('提交成功');
}
});
});
});
</script>