例如:前台是
<tr>
<td width="15%" align="right">会员名称:</td>
<td width="85%" align="left"><input type="text" size="40" name="username" value="{$rss.username}" />
</td>
</tr>
我在后台如何获取 前台 里面 input的值呢,还有就是 <select>标签里面的值?
第一种 表单提交
//地址添加提交
$(function () {
$('#address_submit').click(function () {
layer.load(1,{time:1000});
var select_country=$('#select_country option:selected').text();//select框
var select_province=$('#select_province option:selected').text();
var select_city=$('#select_city option:selected').text();
var consignee=$('#consignee').val();
var phone=$('#phone').val();
var address_detail=$('#address_detail').val();
if(!select_country || !select_province || !consignee || !phone || !address_detail){
layer.msg('Please complete the receipt information', {icon: 2,offset: '100px',time:'1200'});
}
$.post("{:U('User/addAddress')}",{
'select_country':select_country,
'select_province':select_province,
'select_city':select_city,
'consignee':consignee,
'phone':phone,
'address_detail':address_detail,
},function (data) {
if(data=='success'){
layer.msg('operation success', {icon: 1,offset: '100px',time:'1000'});
setTimeout("window.location.reload()",1000);
}
else{
if (data == 'no_session') {
layer.msg('Login information has failed please log in again ', {icon: 2, offset: '100px', time: '1000'});
setTimeout("location.href = '{:U("index/Login/login")}'", 1000);
return false;
}
layer.msg(JSON.stringify(data), {icon: 2,offset: '100px',time:'1500'});
return false;
}
},'json');
});
})
</script>
第二种 ajax 要用你input框的id和select框的id
<script>//地址添加提交
$(function () {
$('#address_submit').click(function () {
layer.load(1,{time:1000});
var select_country=$('#select_country option:selected').text();//select框
var select_province=$('#select_province option:selected').text();
var select_city=$('#select_city option:selected').text();
var consignee=$('#consignee').val();
var phone=$('#phone').val();
var address_detail=$('#address_detail').val();
if(!select_country || !select_province || !consignee || !phone || !address_detail){
layer.msg('Please complete the receipt information', {icon: 2,offset: '100px',time:'1200'});
}
$.post("{:U('User/addAddress')}",{
'select_country':select_country,
'select_province':select_province,
'select_city':select_city,
'consignee':consignee,
'phone':phone,
'address_detail':address_detail,
},function (data) {
if(data=='success'){
layer.msg('operation success', {icon: 1,offset: '100px',time:'1000'});
setTimeout("window.location.reload()",1000);
}
else{
if (data == 'no_session') {
layer.msg('Login information has failed please log in again ', {icon: 2, offset: '100px', time: '1000'});
setTimeout("location.href = '{:U("index/Login/login")}'", 1000);
return false;
}
layer.msg(JSON.stringify(data), {icon: 2,offset: '100px',time:'1500'});
return false;
}
},'json');
});
})
</script>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2018-07-11
如果用from表单提交注意get post方法
如果get方法 直接
<a href="{:U('index/get')}?name={$rss.username}&sex={$rss.你想要的值}">后台直接get方法获得参数
from 表单的话用action提交 后台获取的是根据name=""获取
在后台用
//POST tp3.2$name=$_POST['username'];
dump($name);
//GET tp3.2
$name=$_GET['username'];
dump($name);
//POST tp5
$name=$_POST['username'];
dump($name);
//GET tp5
$name=input('param.name');
dump($name);
第2个回答 2013-12-09
找到form表单中action对应的控制器内,用$_GET['username'] (input的name名) 来获取值
第3个回答 2013-12-09
这个不好说啊
只能建议你去看教程了
不过感觉您这个后台怎么获取这个说法貌似有些别扭
由于thinkphp是基于mvc框架开发的
所以只能说你得找到你这个form对应的action方法
然后和一般的php一样根据form的method的方式选择POST或则GET来获取追问
只能建议你去看教程了
不过感觉您这个后台怎么获取这个说法貌似有些别扭
由于thinkphp是基于mvc框架开发的
所以只能说你得找到你这个form对应的action方法
然后和一般的php一样根据form的method的方式选择POST或则GET来获取追问
- -后台没得办法获取到 input里面的值啊?
追答额,能贴一下你的action里面的方法如何获取的吗
或则说你的form 的action对应的方法不是你当前写的这个方法
<form action="{:U('huiyuan_edit')}" id="frmDemo" method="post" name="form1" >
额,我有些凌乱了你不是input的name是username吗,怎么get的是id啊
追问$id是从另外一个页面用get方式传过来的。。不用管的
追答我只能说按照你当前的方法来看你没继承行为类
本回答被提问者和网友采纳第4个回答 2018-07-26
你前台的提交方式如果是post方式的话,后台就用$_POST['username'],如果是get的话就是$_GET['username'],或者直接用$_REQUEST['username'],$_REQUEST默认是$_GET, $_POST的集合