2

如何获取所选单选按钮的值。将其用作绘制矩形(或圆形)的坐标。最终我想为相同目的获得所有答案的平均值。

这是我的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" />'; 
?>
4

2 回答 2

0

您正在使用 GET,所以它很简单

$val = $_GET['g1'];

对于 POST,它将是$_POST[<name>].

于 2012-10-02T22:26:32.360 回答
0

In php, to get that code you could add a submit button then you get the values through $_POST

example: $_POST['g1']

于 2012-10-02T22:27:26.320 回答