duandan4680 2015-06-03 15:02
浏览 72
已采纳

使用PHP DOM获取提交的值

I want to get the values that belong to the answers of a test. There could be any number of questions. A question has the HTML:

<form method='post' action='calificar.php'>

<div class='pruebaAlumno'>

    <h5>Pregunta 3</h5>
    <h3>¿Que factores definen la capacidad de una persona?</h3>

    <input type='checkbox' name='respuestaAlumno[]' 
                      value='Voluntad'> Voluntad <br>
    <input type='checkbox' name='respuestaAlumno[]' 
                      value='Cultura'> Cultura <br>
    <input type='checkbox' name='respuestaAlumno[]' 
                      value='Hábitos'> Hábitos <br>
    <input type='checkbox' name='respuestaAlumno[]' 
                      value='Habilidad'> Habilidad <br>
    <input type='checkbox' name='respuestaAlumno[]' 
                      value='Perfil'> Perfil <br>
    <input type='checkbox' name='respuestaAlumno[]' 
                      value='Dones'> Dones <br>

    <input type='hidden' name='idPregunta' value='41'>
    <input type='hidden' name='tipo' value='C'>
             </fieldset>

            </div>  <div class='calificar'>
                    <input type='submit' name='calificar' value='enviar' >
                </div>
            </form>

I want to get

  1. Answer (respuestaAlumno)
  2. questionID (idPregunta)
  3. type (tipo)

from each question.

Then I want to save the data in an array.

A test can have as many questions as the teacher wants. The form has one submit button.

I´ve tried to get the data in different ways. Using JS DOM. Using POST. I´ve found some PHP DOM tutorials but them all teach how to modify an static HTML.
Please help me to get the submitted data from each fieldset. Thanks in advance.

  • 写回答

2条回答 默认 最新

  • doutan1857 2015-06-03 15:15
    关注

    You could format your form names like this.

    First question

    name="respuestaAlumno[0][]"
    name="respuestaAlumno[0][]"
    ...
    name="idPregunta[0]"
    name="tipo[0]"
    

    Second question

    name="respuestaAlumno[1][]"
    name="respuestaAlumno[1][]"
    ...
    name="idPregunta[1]"
    name="tipo[1]"
    

    You would end up with three arrays in your $_POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码