如何获取所选单选按钮的值。将其用作绘制矩形(或圆形)的坐标。最终我想为相同目的获得所有答案的平均值。
这是我的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" />'; 
?>