我正在處理提交給要轉換爲文本文件的服務器的表單視圖。視力需要將數據發佈到服務器端的php。還需要在URL中添加「?PART_NO = 部分 & frm = MF001」以命名每個文本文件。
如果表單包含多個單選按鈕,它會使JavaScript崩潰。這可能是因爲我試圖訪問表單元素的方式。我只需要訪問名稱爲「Part_No」的文本字段。HTML單選按鈕崩潰JavaScript表單功能
<!DOCTYPE html>
<html>
<body>
<form id="test" method="post" action="http://10.0.0.252/test.php" onsubmit="process()">
<input type="checkbox" tabindex="40" id="form67_1" data-objref="458 0 R" name="box_brown" imageName="1/form/416 0 R" images="110100"/>
<input type="radio" tabindex="32" id="form68_1" data-objref="495 0 R" name="rc-50" value="yes" imageName="1/form/497 0 R" images="110100" checked="checked"/>
<input type="radio" tabindex="31" id="form69_1" data-objref="494 0 R" name="a2262at" value="no" imageName="1/form/494 0 R" images="110100"/>
<input type="radio" tabindex="17" id="form70_1" data-objref="509 0 R" name="process" value="no" imageName="1/form/509 0 R" images="110100"/>
<input type="radio" tabindex="11" id="form71_1" data-objref="503 0 R" name="master_glass" value="no" imageName="1/form/503 0 R" images="110100"/>
<input type="text" tabindex="4" id="form129_1" value="2" data-objref="62 0 R" title="Part No." name="Part_No"/>
<input type="submit" value="Submit">
</form>
<script>
function process() {
var form = document.getElementById('test');
var elements = form.elements["Part_No"];
var values = [];
values.push(encodeURIComponent(elements.name) + '=' + encodeURIComponent(elements.value) + "&frnm=MF001");
form.action += '?' + values;
}
</script>
</body>
</html>
這裏的服務器端腳本,如果有人有興趣。
<?php
$name = $_GET['Part_No'];
$nom = $_GET['frnm'];
ob_start();
$file = $GLOBALS['HTTP_RAW_POST_DATA'];
$time = microtime(true);
$newfile = "./customers/" . $nom . "." . $name . "." . $time . ".txt";
$worked = file_put_contents($newfile, $file);
ob_end_clean();
exit();
?>
沒有ID爲「」Part_No「的_text字段_ ... –
」「對不起,我的意思是姓名 –