2

私はPHPにまったく慣れておらず、現在調査を行っています。ユーザーは、ラジオ ボタンでフォームの質問に対する回答を選択します。各質問には 4 つの可能性があり、各質問の下にグループ化されています。フォームが送信されると、各グループのどのボタンが選択されたかがページに表示されます。現時点でのコードは次のとおりです。

<form action="thankyou.php" method="post">
  <p>How easy would you say it is to create new carers?</p>
   <input type="radio" name="rgroup1" value="rg1v1"> Excellent
   <input type="radio" name="rgroup1" value="rg1v2"> Good
   <input type="radio" name="rgroup1" value="rg1v3"> Average
   <input type="radio" name="rgroup1" value="rg1v4"> Poor</br>

  <p>How easy is it to generate a report?</p>
   <input type="radio" name="rgroup2" value="rg2v1"> Excellent
   <input type="radio" name="rgroup2" value="rg2v2"> Good
   <input type="radio" name="rgroup2" value="rg2v3"> Average
   <input type="radio" name="rgroup2" value="rg2v4"> Poor</br>

  <p>How easy is it to add and alter timesheets?</p>
   <input type="radio" name="rgroup3" value="excellent"> Excellent
   <input type="radio" name="rgroup3" value="good"> Good
   <input type="radio" name="rgroup3" value="average"> Average
   <input type="radio" name="rgroup3" value="poor"> Poor</br>

  <p>How good would you rate the Packages Of Care functions? </p>
   <input type="radio" name="rgroup4" value="excellent"> Excellent
   <input type="radio" name="rgroup4" value="good"> Good
   <input type="radio" name="rgroup4" value="average"> Average
   <input type="radio" name="rgroup4" value="poor"> Poor</br>

  <p>Question 5</p>
   <input type="radio" name="rgroup5" value="excellent"> Excellent
   <input type="radio" name="rgroup5" value="good"> Good
   <input type="radio" name="rgroup5" value="average"> Average
   <input type="radio" name="rgroup5" value="poor"> Poor</br>
   </br>
      Please  Enter Your Comments Below:
   </br></br>
        <textarea name="comments" width="100px" rows="4" cols="50" wrap="wrap"></textarea>
   </br></br>
        <input type="submit">
   <br/><br/>
</form>

「thankyou.php」ページの私のPHPは次のとおりです。

<?php 

switch($_POST['rgroup1']) {
    case "rg1v1":
        $value = "Radio Group 1 - Value 1 was selected.";
        break;
    case "rg1v2":
        $value = "Radio Group 1 - Value 2 was selected.";
        break;
    case "rg1v3":
        $value = "Radio Group 1 - Value 3 was selected.";
        break;
    case "rg1v4":
        $value = "Radio Group 1 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 1";
}

switch($_POST['rgroup2']) {
    case "rg2v1":
        $value2 = "Radio Group 2 - Value 1 was selected.";
        break;
    case "rg2v2":
        $value2 = "Radio Group 2 - Value 2 was selected.";
        break;
    case "rg2v3":
        $value2 = "Radio Group 2 - Value 3 was selected.";
        break;
    case "rg2v4":
        $value2 = "Radio Group 2 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 2";
}

switch($_POST['rgroup3']) {
    case "rg3v1":
        $value3 = "Radio Group 3 - Value 1 was selected.";
        break;
    case "rg3v2":
        $value3 = "Radio Group 3 - Value 2 was selected.";
        break;
    case "rg3v3":
        $value3 = "Radio Group 3 - Value 3 was selected.";
        break;
    case "rg3v4":
        $value3 = "Radio Group 3 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 3";
}

switch($_POST['rgroup4']) {
    case "rg4v1":
        $value4 = "Radio Group 4 - Value 1 was selected.";
        break;
    case "rg4v2":
        $value4 = "Radio Group 4 - Value 2 was selected.";
        break;
    case "rg4v3":
        $value4 = "Radio Group 4 - Value 3 was selected.";
        break;
    case "rg4v4":
        $value4 = "Radio Group 4 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 4";
}

switch($_POST['rgroup5']) {
    case "rg5v1":
        $value5 = "Radio Group 5 - Value 1 was selected.";
        break;
    case "rg5v2":
        $value5 = "Radio Group 5 - Value 2 was selected.";
        break;
    case "rg5v3":
        $value5 = "Radio Group 5 - Value 3 was selected.";
        break;
    case "rg5v4":
        $value5 = "Radio Group 5 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 5";
}


echo $value;
echo $value2;
echo $value3;
echo $value4;
echo $value5;

?>

value2、3、4、および 5 の変数を定義していないというエラーが表示されますが、その理由がわかりません。

4

3 に答える 3

2

3、4、および5の場合、radioセクション値は優れており、良好、平均、不良であり、機能していません。「rg3v1」、「rg3v2」、「rg3v3」、および「rg3v4」。したがって、実行が次のコードに入ると、

switch($_POST['rgroup3']) {
    case "rg3v1":
        $value3 = "Radio Group 3 - Value 1 was selected.";
        break;
    case "rg3v2":
        $value3 = "Radio Group 3 - Value 2 was selected.";
        break;
    case "rg3v3":
        $value3 = "Radio Group 3 - Value 3 was selected.";
        break;
    case "rg3v4":
        $value3 = "Radio Group 3 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 3";
}

switch($_POST['rgroup4']) {
    case "rg4v1":
        $value4 = "Radio Group 4 - Value 1 was selected.";
        break;
    case "rg4v2":
        $value4 = "Radio Group 4 - Value 2 was selected.";
        break;
    case "rg4v3":
        $value4 = "Radio Group 4 - Value 3 was selected.";
        break;
    case "rg4v4":
        $value4 = "Radio Group 4 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 4";
}

switch($_POST['rgroup5']) {
    case "rg5v1":
        $value5 = "Radio Group 5 - Value 1 was selected.";
        break;
    case "rg5v2":
        $value5 = "Radio Group 5 - Value 2 was selected.";
        break;
    case "rg5v3":
        $value5 = "Radio Group 5 - Value 3 was selected.";
        break;
    case "rg5v4":
        $value5 = "Radio Group 5 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 5";
}

次の変数を出力しようとすると、何も割り当てられず、エラーが表示されます。

echo $value3;
echo $value4;
echo $value5;
于 2013-02-19T12:34:16.320 に答える
2

rgroup 3、4、および 5 の場合、値は rgroup1 および rgroup2 として期待される形式ではありません。値を優れた、良いなどの文字列として入れましたが、これはスイッチのケースと一致しません。

于 2013-02-19T12:30:53.433 に答える
0

同じ名前のスイッチケースのすべてのデフォルト変数。したがって、オプションが選択されていない場合は、php の値変数を使用します。それに応じて他のデフォルト値を変更してください。

<?php 

switch($_POST['rgroup1']) {
    case "rg1v1":
        $value = "Radio Group 1 - Value 1 was selected.";
        break;
    case "rg1v2":
        $value = "Radio Group 1 - Value 2 was selected.";
        break;`enter code here`
    case "rg1v3":
        $value = "Radio Group 1 - Value 3 was selected.";
        break;
    case "rg1v4":
        $value = "Radio Group 1 - Value 4 was selected.";
        break; 

        default:
        $value = "No radio has been selected for Radio Group 1";
}

switch($_POST['rgroup2']) {
    case "rg2v1":
        $value2 = "Radio Group 2 - Value 1 was selected.";
        break;
    case "rg2v2":
        $value2 = "Radio Group 2 - Value 2 was selected.";
        break;
    case "rg2v3":
        $value2 = "Radio Group 2 - Value 3 was selected.";
        break;
    case "rg2v4":
        $value2 = "Radio Group 2 - Value 4 was selected.";
        break; 

        default:
        $value2 = "No radio has been selected for Radio Group 2";
}

switch($_POST['rgroup3']) {
    case "rg3v1":
        $value3 = "Radio Group 3 - Value 1 was selected.";
        break;
    case "rg3v2":
        $value3 = "Radio Group 3 - Value 2 was selected.";
        break;
    case "rg3v3":
        $value3 = "Radio Group 3 - Value 3 was selected.";
        break;
    case "rg3v4":
        $value3 = "Radio Group 3 - Value 4 was selected.";
        break; 

        default:
        $value3 = "No radio has been selected for Radio Group 3";
}

switch($_POST['rgroup4']) {
    case "rg4v1":
        $value4 = "Radio Group 4 - Value 1 was selected.";
        break;
    case "rg4v2":
        $value4 = "Radio Group 4 - Value 2 was selected.";
        break;
    case "rg4v3":
        $value4 = "Radio Group 4 - Value 3 was selected.";
        break;
    case "rg4v4":
        $value4 = "Radio Group 4 - Value 4 was selected.";
        break; 

        default:
        $value4 = "No radio has been selected for Radio Group 4";
}

switch($_POST['rgroup5']) {
    case "rg5v1":
        $value5 = "Radio Group 5 - Value 1 was selected.";
        break;
    case "rg5v2":
        $value5 = "Radio Group 5 - Value 2 was selected.";
        break;
    case "rg5v3":
        $value5 = "Radio Group 5 - Value 3 was selected.";
        break;
    case "rg5v4":
        $value5 = "Radio Group 5 - Value 4 was selected.";
        break; 

        default:
        $value5 = "No radio has been selected for Radio Group 5";
}


echo $value;
echo $value2;
echo $value3;
echo $value4;
echo $value5;

?>
于 2013-02-19T12:36:19.113 に答える