【发布时间】:2014-02-15 06:30:17
【问题描述】:
我在 codeigniter 中有一个 php 应用程序,我遇到了以下问题。 使用 Ipad 随机提交表单时,会丢失发布数据。 我尝试了四种不同的方式访问帖子数据。
print_r($this->input->post());
print_r($_POST);
print_r(file_get_contents('php://input'));
print_r($_REQUEST);
所有这些都没有返回任何内容或一个空数组。 这似乎只在使用 Ipad 或 Iphone 时发生,但在桌面 safari 的 50 多次测试中发生过一次。 在 PC 浏览器上测试大约 100 次(firefox、chrome、IE)时,它没有发生,只有一次在 safari 中。
表格的代码;
<form id="email_report_form" name="email_report_form" method="post" accept-charset="utf-8" action="/handleajax/email_page" class="email_report_form ajaxform" onsubmit="return validate();">
<div class="form_step_container clearfix">
<div class="element clearfix">
<div class="col_left">
<label>Email: <span class="required">*</span></label>
</div>
<div class="col_right">
<input type="text" name="form_email_to" id="form_email_to" />
<div> </div>
<label>Separate multiple email addresses with a comma</label>
</div>
</div>
<div class="element clearfix">
<div class="col_left">
<label>Your Message:</label>
</div>
<div class="col_right">
<textarea name="form_email_message" cols="125" rows="5" onkeypress="return checkLength(event, this, 1000);"></textarea>
<label>(Maximum of 1000 characters)</label>
<br />
<input type="hidden" name="redirect_path" id="redirect_path" value="" />
<input type="submit" value="Send" class="btn btn-primary" />
</div>
</div>
</div>
<div class="element clearfix">
<i>Information entered in this form will not be used for marketing purposes or passed to third parties.</i>
</div>
</form>
onSubmit validate() 的代码;
function validate() {
element = document.getElementById("form_email_to");
addresses = element.value.split(",");
for (var i = 0; i < addresses.length; i++) {
address = addresses[i].replace(/^\s*|\s*$/g, "");
if (!validateEmail(address)) {
alert('The email address "' + address + '" is invalid.');
element.focus();
return false;
}
}
if (window.location.hash.length > 2) {
$('#redirect_path').val(window.location.hash.substring(2));
} else {
$('#redirect_path').val(window.location);
}
$('#email_report').slideUp();
return true;
}
表单提交到的函数的代码;
public function email_page() {
echo "<br/>ci<br/>";
print_r($this->input->post());
}
如您所见,这是我正在回显帖子数据的地方,此时数据已丢失。 有谁知道我为什么会遇到这个问题以及如何解决它?
【问题讨论】:
-
我认为代码中没有任何错误,请检查config.php文件,尤其是csrf_protection。
-
可能的原因可能是 302 或 301 重定向。您将表单提交到 /handleajax/email_page。如果您的网络服务器或 php 将用户重定向到另一个位置,您将丢失表单数据。当是 301 永久重定向时,大多数浏览器在重定向一次后会自动转到新位置。这只是众多可能性之一,但很容易检查。
-
你用的是真ipad还是ipad模拟器?
-
@jan 你可以看到我在 emai_page 函数的第一行丢失了表单数据,并且之前没有任何重定向。
-
@Nouphal.M 我使用的是真正的 Ipad 5.1.1 版
标签: javascript php codeigniter post