PHP表单从id而不是值发送值 [英] PHP Form sending value from an id instead of value
问题描述
我通常做的是一个隐藏字段的形式:
What I have typically been doing is something like this in a form with a hidden field:
<input type="hidden" name="someName" value="someVal" />
,我已经能够获得像简单的一样的价值,如
and I have been able to get the value with something simple like
$someVar = $_REQUEST['someVal'];
但是现在我试图通过这样的东西发送DOM元素id中的所有值p>
But now I am trying to send all the values in a DOM element id by something like this
<input type="hidden" name="someNewName" id="element_id_name" />
我正在这样做?这甚至可以做到吗?还是我要走了?
如何从最后一行获取值?或者如何以正确的方式发送数据请求?
I am doing this correctly? Can this even be done? Or am I way off? How do I get the value out of the last line? Or how do I send that data to to request in a correct way?
谢谢,
Alex
Thanks, Alex
推荐答案
你不能通过ID检索php中的数据,它的名称可以用来改变
you cant not retrieve data in php via ID it works on name..so you neeed to change
<form method="POST" action="nextpage.php" name="myform" id="myform">
<input type="text" id="rout_markers" name="rout_markers"/>
<input type="hidden" name="someNewName" id="someNewName" value="" />
<input type="submit" id="send-btn" class="button" value="SEND NOW" onclick="submitform()" />
</form>
jQuery
jQuery
$("form").bind('submit',function(e){
e.preventDefault();
var hiddenData=$("input[name=rout_markers]").val();
// or var hiddenData=jQuery('#rout_markers').val();
$("input[type=hidden][name=someNewName]").val(hiddenData);
});
on
以下方式检索数据
$ _ POST ['someNewName'];
$_POST['someNewName'];
更新
set onclick = submitform() code>在提交按钮,并分配
名称
和 id
属性来形成和写这个
update
set onclick=submitform()
in submit button and also assign name
and id
attribute to form and write this
<script type="text/javascript">
function submitform()
{
var hiddenData = document.getElementById('rout_markers').value;
document.getElementById('someNewName').value = hiddenData;
document.myform.submit();
}
</script>
这篇关于PHP表单从id而不是值发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!