html 表单未从调查中获取正确的变量

html form not grabbing correct variables from survey

我正在构建一个从学生那里收集信息的调查表,使用 HTML(也可以使用 javascript)并且在网上找到了几个例子,但 none 似乎有效.调查表目前只选择了这些:

调查应该选择所有选项(名字、姓氏、居住地、大学选择、专业、校园参观),我不知道如何解决这个问题。

这是调查和代码:

 <h3> Senior Survey </h3>
    <div class="w3-container">

      <script type="text/javascript">
        console.log("Prospective student form is about to be displayed.");
      </script>

      <form method="post" action="mailto:hernand_gabr@bentley.edu" method="GET" enctype="text/plain" name="seniorsurvey">
        <table class="w3-table w3-blue" id="second-gradient">
          
          <tr>
            <td style="text-align: center";> 
            <p><b> Please enter your first and last names. </b></p>
            <input type="text" id="firstname" maxlength="60" placeholder="First Name:"/> 
            <input type="text" id="lastname" maxlength="60" placeholder="Last Name:"/>  
            </td>
          </tr>

          <tr>
            <td style="text-align: center";> 
              <p><b> Where do you live? </b></p>
              <input type="radio" id="peru" name="radiobutton" value="Peru">
              <label for="peru">Peru</label>

              <input type="radio" id="southamerica" name="radiobutton" value="SA">
              <label for="southamerica">South America</label>

              <input type="radio" id="unitedstates" name="radiobutton" value="USA">
              <label for="unitedstates">United States</label> 
            </td>
          </tr>

          <tr>
            <td>
              <fieldset style="text-align: center";>
                <p><b> What were your other top college choices? </b></p>
                <input type="checkbox" id="bentley" name="uni">
                <label for="bentley">Bentley U.</label>

                <input type="checkbox" id="brandeis" name="uni">
                <label for="brandeis">Brandeis U.</label>
                
                <input type="checkbox" id="boston" name="uni">
                <label for="boston">Boston U.</label>
                
                <input type="checkbox" id="babson" name="uni">
                <label for="babson">Babson U.</label>     
                
                <input type="checkbox" id="northeastern" name="uni">
                <label for="northeastern">Northeastern U.</label>               
              </fieldset>
            </td>
          </tr>

          <tr>
            <td style="text-align: center";> 
              <p><b> What is your prospective major? </b></p>
              <select name="majors" id="majors">
                <option value="un">undecided</option>
                <option value="cis">Computer Information Systems</option>
                <option value="fi">Finance</option>
                <option value="acc">Accounting</option>
                <option value="ci">Creative Industries</option>
                <option value="mkt">Marketing</option>
              </select>
              <br>
            </td>
          </tr>

          <tr>
            <td style="text-align: center";> 
              <p><b> When do you plan to visit campus? </b></p>
              <input type="date" id="start" name="visit-start" value="2021-10-25" min="2021-10-25" max="2030-12-31">
              <br><br>
            </td>
          </tr>

          <tr>
            <td style="text-align: center";> 
              <button type="submit" value="Submit College Info"> Submit </button>
              <button type="reset" value="Clear College Info"> Clear  </button>
              <br><br>
            </td>
          </tr>

        </table>
      </form>      

    </div>

您的一些表单字段,例如

<input type="text" id="firstname" maxlength="60" placeholder="First Name:"/> 

没有 name 参数,这是使数据正确发送到服务器的粘合剂。您需要将该行更改为:

<input type="text" name="firstname" id="firstname" maxlength="60" placeholder="First Name:"/> 

基本上只是在其中添加 name="firstname"。你必须再次做同样的事情,为 id="lastname"-input 添加 name="lastname"


3行<input type="radio"行全部使用name="radiobutton";从技术上讲,这没有错,但是考虑到上下文,您可能希望将所有 3 个更改为 name="country" 或类似的内容。这 3 个 应该 相同(因为人们只能选择这 3 个国家中的 1 个,而不是 2 个或 3 个,也不是 0 个)。


5 <input type="checkbox" 行都使用 name="uni",这可能是错误的(虽然我实际上不能肯定地说)。人们可以选择它们的任意组合。您可能希望将它们更改为 5 个不同的名称(例如第一个名称中的 name="uni_bentley",...),或者您可能希望将它们全部保持不变。也许两者都试一下,看看您更喜欢 2 个结果中的哪一个(select 提交时 uni 的 few/all)。