隐藏HTML表单在PHP与javascript


hidden html form in php with javascript

我试图在php中通过HTML表单参数,我有一个php页面,填充HTML表:

$html = '';
$html .= '<form id="form1" action="search.php" method="post">';
$html .= '<tr>';
$html .= '<td>id</td>';
$html .= '<td><a href="javascript:;"onclick="document.getElementById(''form1'').submit();">name</a></td>';
$html .= '<td>surname</td>';
$html .= '<td>language_id</td>';
$html .= '<td><span class="label label-success">Status_code</span></td>';
$html .= '</tr>';
$html .= '<input type="hidden" name="mess" value=''Hello''>';
$html .= '</form>';

我可以看到在我的html表,当我点击href,搜索。php页面打开,但我看不到'Hello'值,这是搜索。php:

<?php
$name0 = $_POST['mess'];
echo $name0;
?>

怎么了?

当你点击href时,你正在打开search.php并试图获得post值是不可能的。

通过附加url传递值,如search.php?混乱= YourValue

或提交表单,以便您可以使用$_POST

进行阅读

在你的表单

<?php
$html = '';
$html .= '<form id="form1" action="search.php" method="post">';
$html .= '<tr>';
$html .= '<td>id</td>';
$html .= '<td><a href="javascript:;"onclick="document.getElementById(''form1'').submit();">name</a></td>';
$html .= '<td>surname</td>';
$html .= '<td>language_id</td>';
$html .= '<td><span class="label label-success">Status_code</span></td>';
$html .= '</tr>';
$html .= '<input type="hidden" name="mess" value=''Hello''>';
$html .= '</form>';
echo $html;
?>
在search.php

<?php echo $_REQUEST['mess'];?>

问题出在你的浏览器而不是php。一个好的浏览器不会显示这个错误。试试这个

<?php
$html = '';
$html = '<table>';
$html .= '<form id="form1" action="search.php" method="post">';
$html .= '<tr>';
$html .= '<td>id</td>';
$html .= '<td><a href="javascript:;"onclick="document.getElementById(''form1'').submit();">name</a></td>';
$html .= '<td>surname</td>';
$html .= '<td>language_id</td>';
$html .= '<td><span class="label label-success">Status_code</span></td>';
$html .= '</tr>';
$html .= '<input type="hidden" name="mess" value=''Hello''>';
$html .= '</form>';
$html .= '</table>';
echo $html;
?>

和search.php

<?php
$name0 = $_POST['mess'];
echo $name0;
?>

我试过了,老实说,我不知道为什么你有这么多的.=所以,我把它们都删掉了

<?php $html = '
<form id="form1" action="search.php" method="post">
<tr>
<td>id</td>
<td><a href="javascript:;"onclick="document.getElementById(''form1'').submit();">name</a></td>
<td>surname</td>
<td>language_id</td>
<td><span class="label label-success">Status_code</span></td>
</tr>
<input type="submit" name="mess" value="Hello">
</form> ';
echo $html;