0

我想从使用 javascript 发送到页面的表单中获取值。这是我的 javascript 函数和表单。

<?php
echo"<html>";
echo"<script type='text/javascript'>";
echo"function submitform(){";
echo"document.getElementById('myform').submit();}";
echo"</script>";
echo"<form id='myform' action='comment.php' method='post'>";                        
echo"<tr>";
echo "<td><img src='photos/$file' alt='$file'><br></td>";
echo "<tr><td><a href=\"delete.php?id=".$file."\" onclick=\"return confirm('You want to delete .$file???');\">".$file."</td></tr>";
echo "<tr><td><a href=\"like.php?id=".$file."\">like</td></tr>";
echo "<tr><td>".$result."likes</td><tr>";   
echo "<tr><td><a href=\"dislike.php?id=".$file."\">unlike</td></tr>";
echo "<tr><td>".$result1."unlikes</td><tr>";
echo"<tr><td colspan='2'>Your Comment: </td>";
$_SESSION['comment']=$file;
echo" <td colspan='5'><textarea name='comment' id='comment' rows='2' cols='25' ></textarea></td></tr>";
echo"<tr><td colspan='2'><a href='javascript: submitform()'>Comment</a></td></tr>";
//echo"<td><form name='up' action='delete.php' method='post' enctype='multipart/form-data></td>";
//echo"<td><a href='http://127.0.0.1/delete.php'><button  name='button' type='submit' value='photos'>delete</button></a></td>";

//$_SESSION['comment']=$file;
echo"</form>";
echo"</tr>";
?>
4

2 回答 2

0

comment.php文件中,值在 $_POST 数组中可用。

$_POST['comment'] // -> what the user wrote in the textarea.
于 2013-09-30T09:51:45.043 回答
0

首先comment.php使用print_r($_POST)并检查数据是否获取。

并且您使用post方法发送数据,以便您可以使用$_POST['field_name'].

并尝试制作像这样的 html、javascript 和 php 代码:

<html>
<script type='text/javascript'>
function submitform(){
   document.getElementById('myform').submit();
}
</script>
<form id='myform' action='comment.php' method='post'>                       
<tr>
 <td><img src='photos/<?php echo $file;?>' alt='<?php echo $file;?>'><br></td>
  :
  :
 </tr>
</form>
</html>
于 2013-09-30T10:00:07.413 回答