【发布时间】:2014-11-16 11:18:23
【问题描述】:
我正在使用引导程序。我正在尝试创建一个工作表单,但提交功能不起作用。 这是我的表单 HTML:
<form class="form-horizontal" role="form" action="mph.php" method="POST">
<div class="modal-body">
<fieldset>
<!-- Form Name -->
<legend>Map Problem Reporter</legend>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">What map?</label>
<div class="col-md-6">
<select id="selectbasic" name="selectbasic" class="form-control">
<option value="1">6 Stages of Parkour</option>
<option value="2">20 Stages of Parkour</option>
</select>
</div>
</div>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="radios">What kind of problem?</label>
<div class="col-md-4">
<div class="radio">
<label for="radios-0">
<input type="radio" name="radios" id="radios-0" value="1">
Blocks
</label>
</div>
<div class="radio">
<label for="radios-1">
<input type="radio" name="radios" id="radios-1" value="2">
Commands / Command Blocks
</label>
</div>
<div class="radio">
<label for="radios-2">
<input type="radio" name="radios" id="radios-2" value="">
Entities / Items
</label>
</div>
<div class="radio">
<label for="radios-3">
<input type="radio" name="radios" id="radios-3" value="">
Other (describe in the next text field)
</label>
</div>
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="textarea">Describe the Problem</label>
<div class="col-md-4">
<textarea class="form-control" id="textarea" name="textarea"></textarea>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">What is the priority?</label>
<div class="col-md-6">
<select id="selectbasic" name="selectbasic" class="form-control">
<option value="1">Huge! It breaks the map!</option>
<option value="2">Big</option>
<option value="">Noticeable</option>
<option value="">Barely Noticeable</option>
<option value="">Almost Hidden</option>
<option value="">I do not know</option>
</select>
</div>
</div>
<input type="submit" name="submit" value="Save Data">
</fieldset>
</form>
这是我当前的 PHP:
<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
$data = $_POST['field1'] . '-' . $_POST['field2'] . "\n";
$ret = file_put_contents('mpr.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
当我单击表单中的“保存数据”时,它不会使用信息更新我的 mpr.txt。请帮忙。
【问题讨论】:
-
1.哪个提交功能? 2.您的表格中的“保存数据”在哪里?还要添加att。表单标签的方法,例如:
<form method="post"> -
答案显而易见! PHP 正在尝试查找已发布的
field1和field2。但是在你的 HTML 表单中你没有定义这两个属性,因此 PHP 不会更新文件! -
人们已经付出了他们的时间来帮助你。请不要通过删除或破坏它来惩罚他们并防止未来的访问者学习。
-
@Flexo 我不是在“惩罚”未来的人,不允许他们看到这一点。我将重新制作线程(一旦它被删除),并更改一些东西。
-
欢迎您改进您的问题,但现在删除它只会浪费那些试图帮助您的人的时间。
标签: php html forms twitter-bootstrap