簡體   English   中英

隱藏的html表單在php中使用javascript

[英]hidden html form in php with javascript

我試圖在PHP中傳遞帶有html表單的參數,我有一個填充html表的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>';

我可以在我的html表中看到,當我點擊href時,它打開了search.php頁面,但是我看不到'Hello'值,這是search.php:

<?php

$name0 = $_POST['mess'];
echo $name0;

?>

怎么了?

正如您在點擊href時所說,您正在打開search.php並嘗試獲取帖子值是不可能的。

通過追加像search.php?mess = YourValue這樣的url來傳遞值

或提交表格,以便您可以閱讀$ _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 $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;

問題是你的瀏覽器不是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;

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM