如何获取所选单选按钮的值。将它用作绘制矩形(或圆形)的坐标。最后,我希望得到所有答案的平均值以达到同样的目的。
以下是我的html表单的代码:
<form id="FormName" action="draw.php" method="get" name="FormName">
<table border="3">
<tr>
<td><span class="hiddenDiv"> Here is my question </span>
</td>
<td><span class="hiddenDiv">
<input type = "radio" name = "g1" id="g1q1" value = "-3" />
</span>
</td>
<td><span class="hiddenDiv">
<input type = "radio" name = "g1" id="g1q2" value = "-2" />
</span>
</td>
<td><span class="hiddenDiv">
<input type = "radio" name = "g1" id="g1q3" value = "-1" />
</span>
</td>
<td><span class="hiddenDiv">
<input name = "g1" type = "radio" id="g1q4" value = "0" />
</span>
</td>
<td><span class="hiddenDiv">
<input type = "radio" name = "g1" id="g1q5" value = "1" />
</span>
</td>
<td><span class="hiddenDiv">
<input type = "radio" name = "g1" id="g1q6" value = "2" />
</span>
</td>
<td><span class="hiddenDiv">
<input type = "radio" name = "g1" id="g1q7" value = "3" />
</span>
</td>
</tr>
</form>
这是我试图使用的draw.php。
<?php
// Create a 55x30 image
$im = imagecreatetruecolor(620, 620);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 130, 130, 130);
$red = imagecolorallocate($im, 255, 0, 0);
$answer = 'g1q1';
//$rrr = $('input[name=g1]:checked','FormName');
// Draw a white rectangle
imagefilledrectangle($im, 0, 0, 620, 620, $white);
imagefilledrectangle($im, 24, 24, 600, 600, $black);
imageline($im, 0, 310, 620, 310, $white);
imageline($im, 310, 0, 310, 620, $white);
imagefilledrectangle($im, $answer*12, $answer*12, $answer*12+12, $answer*12+12, $red);
//imagefilledellipse
// Save the image
imagepng($im, './imagefilledrectangle.png');
imagedestroy($im);
//Get the file
$content = file_get_contents('./imagefilledrectangle.png');
echo '<img src="'.$snippet_theme.'./imagefilledrectangle.png" />';
?>
答案 0 :(得分:0)
你正在使用GET,所以它就像
一样简单$val = $_GET['g1'];
对于POST,它将是$_POST[<name>]
。
答案 1 :(得分:0)
在php中,要获取该代码,您可以添加一个提交按钮,然后通过$_POST
示例:$_POST['g1']