0

テキストエリアの投稿値が処理されないことがあります。問題は、textarea 27 と 30 の値が断続的に欠落していることです。これはブラウザーの問題ではなく、データ長の問題でもないようです。

これはフォームhtmlです:

  <div id="surveycontainer">
      <form method="POST" action="blog/questions" name="exitform">
      <input id="pnum" type="hidden" name="pagenum" value="3"/>

      <div class="qsection">
        <p> 
          27.  Suppose that a friend from another nation comes to see you and doesn’t know about the U.S. economy. How would you <span style="font-style:italic">describe the economy</span> to your friend?  Please actually write the words you would say as specifically as possible.
        </p>
        <textarea id="mlq1" name="27" cols="50" rows="5"></textarea>
      </div>

      <div class="qsection">
        <p> 
          28. What is your opinion about the future of the U.S. economy? Do you think that over the next few months the U.S. economy will improve, become worse, or stay the same?
        </p>
          <input type="radio" name="28" value="-2"><span class="radiotext">-2 (Greatly worse)</span><br/>
          <input type="radio" name="28" value="-1"><span class="radiotext">-1 (Worse)</span> <br/>
          <input type="radio" name="28"  value="0"><span class="radiotext">0 (Stay the same)</span> <br/>
          <input type="radio" name="28" value="1"><span class="radiotext">1 (Better)</span> <br/>
          <input type="radio" name="28" value="2"><span class="radiotext">2 (Much better)</span>
      </div>

      <div class="qsection">
        <p> 
          29. What are the reasons for your prediction? Explain or list them.
        </p>
        <textarea id="mlq2" name="29" cols="50" rows="5"></textarea>
      </div>

      <div class="qsection">
        <p> 
          30. What do you suggest as a solution to improve the U.S. economy?
        </p>
        <textarea id="mlq3" name="30" cols="50" rows="5"></textarea>
      </div>

そして、ここに処理phpがあります:

private function processAnswers($pid) 
  {
    date_default_timezone_set('America/Chicago');
    $created = date("Y-m-d H:i:s");

    foreach($_POST as $key=>$value) {
      if ($key == "pagenum")
        continue;
      // echo "$key: $value \n";
      $sql = "insert into default_answers (participant_id, answer_id, answer_value, created) values (" . $pid . ",'" . htmlspecialchars($key) . "','" . htmlspecialchars($value) . "', '" . $created . "')"; 
      // echo $sql;
      $this->db->query($sql);
    }   
  }

これを呼び出すコードは次のとおりです。

if (isset($_POST['pagenum'])) {
  $pagenum = $this->input->post('pagenum');

  $this->processAnswers($pid);
}

ありがとう

4

1 に答える 1