【发布时间】:2015-12-24 08:56:15
【问题描述】:
在我的表单中,我使用的是 dropzoneJS。我试图在我的数据库中成功提交用户数据和图像后重定向用户。这就是我试图做到的方式。 我的表格 -
if(!empty($_POST)){
$userID = addUser() //This function create new user and return user id
if (!empty($_FILES)) {
//I have function here which will submit user images in a directory an create image path in DB table
}
HEADER('LOCATION: view.php?id='.$userID);//User redirected to their profile page
}//If ends
表格开始:-
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" class="dropzone form-horizontal" id="my-awesome-dropzone" method="post" enctype="multipart/form-data">
<input type blah.. blah..>
<input type blah.. blan..>
<!-- DropzoneJS div -->
<div class="dropzone-previews form-group" style="height: 350px;"></div>
<div class="fallback col-xs-3">
<input name="file" class="input-file form-control "type="file" multiple/>
</div>
<button type="submit" id="submit-all" class="btn btn-primary">Submit</button>
</form>
然后是 DropzoneJS 设置
<script type="text/javascript">
Dropzone.options.myAwesomeDropzone = {
autoProcessQueue: false,
blah.. blah
blah.. blah
init: function() {
var myDropzone = this;
$("#submit-all").click(function (e) {
e.preventDefault();
e.stopPropagation();
if (myDropzone.files.length) {
myDropzone.processQueue(); // upload files and submit the form
} else {
$('#my-awesome-dropzone').submit(); // submit the form
}
});
}
}
</script>
现在,当用户填写并提交表单(dropzone 字段中没有图片)时,用户数据会提交到我的数据库中,并且用户已成功重定向到他们的个人资料页面 (mywebsite.com/view.php?id=1)。这可以。
但问题是—— 当用户填写并提交表单(在 dropzone 字段中包含图像)时,用户数据和图像都成功提交到我的数据库中,因为所需的重定向没有发生。这不好。为什么没有发生重定向?
请指出哪里错了。
【问题讨论】:
标签: php dropzone.js