0

我正在尝试提交<span>要通过 php 邮寄的值。

我想提交变量 span res1

<form method="POST" name="results" action="message.php">
      <span id="res1">Mail This:*this part varies*</span>
</form>

使用这个处理程序:

$body .= $_REQUEST['#res1']." \n";
mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be sent.");

我宁愿<span>不在表格中;我不确定这是否可能?

原谅我的无知 - 以前从未使用过服务器端的东西!感谢任何可以帮助我的人!

4

2 回答 2

0

这部分如何变化到跨度?使用相同的指令添加一个

<input type="hidden" name="res1" value="the same value you put in the span"/>

然后,在您的 PHP 代码中,您可以使用$_REQUEST['res1']$_POST['res1']-- 注意删除的哈希值来获取值。

更新

对于任何可能犯类似错误的人,这里是什么可行,什么不可行。

HTML 表单仅在提交时发送表单控件的值。他们是:

  • inputs of various types (text, password, radio, checkbox, hidden, file, submit, image, or newer HTML5 inputs like email, etc.)
  • selects
  • textareas

Furthermore, the value of an input is only submitted if it has been assigned a name. So if the following inputs are in a form, on submitting the form whatever value bugs may have will be submitted, but nothing will be submitted for bunny:

<input type="text" name="bugs"/>
<input type="text" id="bunny"/>

So, putting any element between <form> ... </form> does not cause the text inside it to be submitted. For a value to be submitted it should be one of the above form controls AND it should have a name property set.

于 2013-03-30T14:41:35.013 回答
0

You can do this:-

<form method="POST" name="results" action="message.php">
  <input type="hidden" id="res1" value="some text" />
</form>

You can use javascript to access and change "res1"

document.getElementById("res1").value=some variable or textbox content;
于 2013-03-30T14:48:33.210 回答