我正在尝试提交申请表。一切都在localhost上完美运行但最近,当我在现场开始测试时,我注意到在提交表单时,某些textareas或输入字段是如何传递给$ _POST的。
表格的摘录:
<form id="apply" action="parseApplication.php" novalidate method="request">
<div class="app-box basic fade">
<p class="required"></p>
<input type="text" name="First name" placeholder="John" required><br>
<p class="required"></p>
<input type="text" name="Last name" placeholder="Doe" required><br>
<p class="required"></p>
<input type="number" name="Age" id="age"required><br>
<p class="required"></p>
<input type="text" name="Twitter handle" placeholder="@username" required><br>
<p></p>
<select id="position" name="Position">
<option value="support-rep">Support Representative</option>
<option value="moderator">Moderator</option>
<option value="build">Build Team Member</option>
<option value="dev">Developer</option>
</select>
<p class="error" style="color: red; display: none">Please fill in all the required fields. <span class="italic">(* = required)</span></p>
<a id="next" onclick="plusApp(1);" href="#">Next →</a>
</div>
<div class="app-box free-answers fade">
<p class="required"></p>
<textarea id="q1" name="Why do you want to work for us?" required></textarea>
<p class="required"></p>
<textarea id="q2" name="Do you have any previous working experience as your desired role? If so, please elaborate." required></textarea>
<p class="required"></p>
<textarea id="q3" name="What should we expect of you to bring into the team?" required></textarea>
从这一部分开始,第一个框的所有字段都按预期提交并写入文件以及textarea q1。但是,q2没有提交到$ _POST。然后q3被提交。这不仅发生在这个特定的部分,而且在其他几个地方也没有特别的原因。一些textareas或数字字段只是被省略。
我的PHP:
<?php
require('applyHeader.php');
echo "<style>#page{display:block;}#loading{display:none;}</style>";
echo "<h1>Thank you for applying, " . $_REQUEST['First_name'] ."!</h1>";
echo "<p>Your application has been submitted and we will notify you once it is reviewed.</p>";
echo "<div class='app-box' style='display:none!important;'></div>"; // to stop jquery errors
$files = new FilesystemIterator(__DIR__ . DIRECTORY_SEPARATOR . "applications", FilesystemIterator::SKIP_DOTS);
$file = fopen(__DIR__ . DIRECTORY_SEPARATOR . "applications" . DIRECTORY_SEPARATOR . iterator_count($files) . ".txt", "a") or die("Something went wrong");
foreach ($_REQUEST as $key => $value) {
fwrite($file, "$key: $value\n");
}
fclose($file);
require('applyFooter.php');
我试过了:
答案 0 :(得分:0)
您的表单method
必须是post
而不是request
。
<form method="post" ...>
</form>
然后,您可以使用$_POST['...']
处理结果。
答案 1 :(得分:0)
您应该更改post
上的表单方法,并在没有空白字符的内容上重命名textareas的名称。而且我也没有在表单中看到提交按钮。您需要名为submit
的此按钮。