我的任务是使用 php 脚本在文本文件中显示保存的 HTML 表单数据。如果用户单击“是”按钮,将启用数据集字段,如果“否”,将启用令牌编号字段。用户将根据他的单选按钮选择导航到页面。请看一下我的代码,让我知道我哪里出错了。提前谢谢这是我的 HTML
<form method="post" action="Input1.php" name="form">
<label> New Data set: </label>
<input type="radio" name="url" value="NetOptInput2.html" id="ex1" required/> Yes
<input type="radio" name="url" value="NetOptResult2.html" id="ex2" required/> No
<br><br><br>
<label>Dataset description:
</label>
<input type="text" name="Dataset" id="field1" size="30" placeholder="" readonly><br><br><br>
<label>Token Number : </label><input type="text" name="Token Number" id="field2" size="6" placeholder="" readonly><br><br><br>
<div style="text-align: center"><br>
<input type="Submit" name="submit" value="Submit" class="submit">
<div class="spacer"></div>
</form>
这是我在 html 中的 JQuery:
<!-- this function navigates user according to the radio button selection-->
<script type="text/javascript">
$(function(){
$('form').submit(function(event){
event.preventDefault();
window.location = $('input[type=radio]:checked').val();
});
});
</script>
<!--This function disables the Token Number form if the user clicks "yes" radio button and disables Dataset if "No"-->
<script type="text/javascript">
$(function(){
$("#ex1, #ex2").change(function(){
$("#field1, #field2").val("").attr("readonly",true);
if($("#ex1").is(":checked")){
$("#field1").removeAttr("readonly");
$("#field1").focus();
}
else if($("#ex2").is(":checked")){
$("#field2").removeAttr("readonly");
$("#field2").focus();
}
});
});
</script>
这是我的PHP:
<?php
if (isset($_POST[submit'])) {
$Dataset = $_POST['Dataset'];
$Token number = $_POST['Token Number'];
$data = "$Dataset | $Token Number\n";
$file = "input.txt";
$fp = fopen($file, "a") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
$message = "Saved to $file successfully!";
}
?>