Reputation: 9273
i'm trying to pass parameter with a html form in php, i have a php page that fill a html table:
$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>';
i can see in my html the table, when i click on the href, the search.php page it's open, but i can't see the 'Hello' value, this is the search.php:
<?php
$name0 = $_POST['mess'];
echo $name0;
?>
what is wrong?
Upvotes: 0
Views: 212
Reputation:
The problem is with your browser not php. a good browser wont show this error. try this
<?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;
?>
and search.php
<?php
$name0 = $_POST['mess'];
echo $name0;
?>
Upvotes: 0
Reputation:
I tried this, honestly I don't know why you have SO many .=
so, I got rid all of them
<?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;
Upvotes: 0
Reputation: 2129
in your form
<?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;
?>
in search.php
<?php echo $_REQUEST['mess'];?>
Upvotes: 1
Reputation: 16086
As you said on click of href you are opening search.php and trying to get post values is not possible.
either pass value by appending the url like search.php?mess=YourValue
or submit the form so that you can read with $_POST
Upvotes: 1