0

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?

4
  • Why do you have mess value in single quotes? place it in double and check again. Commented Apr 1, 2013 at 10:00
  • I think you should not append your html files like that, maybe remove all .= and just see what happens Commented Apr 1, 2013 at 10:01
  • missing $ in html @first line Commented Apr 1, 2013 at 10:01
  • there is the $, i forget to write it here, but in my code there is, i edit the question... Commented Apr 1, 2013 at 10:09

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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'];?>

1 Comment

That's not so much an answer to the question as it's a way to debug what's going on.
0

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;

?>

7 Comments

I made some changes in the first form too. it is working here.
not work to me...and the first form it's equal to mine...what changes have you made?
I guess, you are opening the search.php directly. open the form first then click the link. i can't believe that you make that error, but you may. as you say this is not working. @piero
i can't understand what is the error, if i write the form above (or mine form) direct in the html code, i can open the search.php page and see the Hello, instead if i use php to generate that $html does not working...open page but there isn't write anything...i can't understand...
i see the html code, and i found the problem: <form id="form1" action="search.php" method="post"></form> , so open and close the form, and i can't understand why do this...
|
0

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;

1 Comment

i use .= because i need it in my code after, it's not that the problem because the html table it's correctly filled...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.