【问题标题】:php loop through submitted form fieldsphp遍历提交的表单字段
【发布时间】:2015-03-24 03:55:20
【问题描述】:

我正在尝试设置来自表单的电子邮件回复,该表单将发回提交的数据。到目前为止,我有

$message= '';
foreach ($_POST as $key => $value)
{
    $message .= $key . ': ' . $value . PHP_EOL;
}

但这会显示所有字段,而不仅仅是具有值的字段。有没有办法只显示提交字段中的名称和值?

【问题讨论】:

  • 这就是 if 语句发挥作用的地方

标签: php forms field


【解决方案1】:

查看 isset 命令的最佳位置 -- here

基本上伪代码是:

//$message initialize
//foreach of the POST values as key value
//if the value isset, then
//concatenate (.=) to message

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 2013-04-09
    • 2013-09-14
    • 2021-04-27
    • 1970-01-01
    相关资源
    最近更新 更多