[英]How to get and send values from html <textarea> to a PHP page?
I created a form for image uploading.我创建了一个用于图像上传的表单。 This form also includes a tag to add information about the image being uploaded.此表单还包括一个标签,用于添加有关正在上传的图像的信息。 I need the text from the tag to be sent over to a page "savetofile.php" whenever 'Upload' button is clicked.每当单击“上传”按钮时,我都需要将标签中的文本发送到页面“savetofile.php”。
Currently the picture uploading works, the picture information is sent correctly, but I can't get the text from the tag on the "savetofile.php" page.目前图片上传正常,图片信息发送正确,但我无法从“savetofile.php”页面的标签中获取文本。
Form形式
<form action="savetofile.php" enctype="multipart/form-data" id="form1" method="post">
<div>
<label for="fileToUpload">Take or select photo(s)</label><br/>
<input accept="image/*" capture id="fileToUpload" name="fileToUpload" onchange="fileSelected();"
type="file"/>
</div>
<div>
<br><br>
<label for="notes">Notes:</label>
<textarea cols="50" id="notes" maxlength="2000" name="notes" placeholder="Please enter any additional information here"
rows="4" onchange="this.form.submit()"></textarea>
<br><br>
</div>
<div id="details"></div>
<div>
<input onclick="uploadFile()" type="button" value="Upload"/>
</div>
<div id="progress"></div>
</form>
savetofile.php保存到文件.php
$text = $_POST['notes'];
_log('text: ' .$text);
uploadFile()上传文件()
function uploadFile() {
var fd = new FormData();
var count = document.getElementById('fileToUpload').files.length;
for (var index = 0; index < count; index++) {
var file = document.getElementById('fileToUpload').files[index];
fd.append('myFile', file);
}
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", "savetofile.php");
xhr.send(fd);
}
Current output:当前 output:
Undefined index: notes...
text:
Seems like you haven't append notes field value.好像您还没有 append 注释字段值。 Add this after for loop,在 for 循环之后添加这个,
fd.append('notes', document.getElementById('notes').value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.