如何通过POST类型通过html表单发送PHP数组 [英] How to send PHP array by html form by POST type
本文介绍了如何通过POST类型通过html表单发送PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过POST发送html表单来发送PHP数组。我使用的代码如下:
<?php
$ content = array('111', '222');
?>
< html>
< head>
< title> PAGE TITLE< / title>
< / head>
< body>
< input type =textname =datavalue =<?php echo $ content;?>/>
< a href =javascript:submitform()>下载< / a>
< / form>
< script type =text / javascript>
函数submitform()
{
document.downloadexcel.submit();
}
< / script>
< / body>
< / html>
如何通过html表单发送PHP数组?
任何网页链接或源代码将不胜感激。
解决方案
你不能像这样发送数组。它将返回 Array
。你可以这样做
< form name =downloadexcelaction =downloadexcel.phpmethod =post >
<?php foreach($ content as $ item):?>
< input type =textname =data []value =<?php echo $ item;?>/>
<?php endforeach?>
< a href =javascript:submitform()>下载< / a>
< / form>
这个变体是最适合在模板或代码中使用的。 HTML
将很容易通过 IDE验证和
代码助手
会也可用。
I am trying to send PHP array by html form by POST. The code which I am using is below:
<?php
$content = array('111', '222' );
?>
<html>
<head>
<title>PAGE TITLE</title>
</head>
<body>
<form name="downloadexcel" action="downloadexcel.php" method="post">
<input type="text" name="data" value="<?php echo $content; ?>"/>
<a href="javascript: submitform()">Download</a>
</form>
<script type="text/javascript">
function submitform()
{
document.downloadexcel.submit();
}
</script>
</body>
</html>
How can I send an PHP array by html form?
Any web link or source code would be appreciated.
解决方案
You can't send array like this. It will return Array
. You can do it this way
<form name="downloadexcel" action="downloadexcel.php" method="post">
<?php foreach ($content as $item): ?>
<input type="text" name="data[]" value="<?php echo $item; ?>"/>
<?php endforeach ?>
<a href="javascript: submitform()">Download</a>
</form>
This variant is the most elegant to use in templates or anywhere in the code. HTML
will be easily validated by IDE
and code assist
will be also available.
这篇关于如何通过POST类型通过html表单发送PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文