duanbei1598 2014-11-15 22:33
浏览 185

Bootstrap - 自定义表单

I am using Bootstrap. I am trying to create a working form, but the submit function doesn't work. Here is my form 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>

And here is my current PHP:

<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
$data = $_POST['field1'] . '-' . $_POST['field2'] . "
";
$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');
}
?>

When I click "Save Data" in the form, it doesn't update my mpr.txt with the information. Please help.

  • 写回答

2条回答 默认 最新

  • duandi6531 2014-11-15 22:45
    关注

    I see 2 problems:

    1) You have created 2 forms with

    <form class="form-horizontal" role="form">
    

    and

    <form class="form-horizontal">
    

    which should be 1

    and

    2) You are missing the action attribute in <form> tag i.e. it should be <form class="form-horizontal" role="form" action="<php file name>" method="<request type>">

    correct these and I think you should be through.

    You do not see the data in your .txt file because you do not have any field named field1 and field2 in your html page. The field names have to match in both html and php files to write/read the data correctly. Please correct the names and you should be through.

    Also would appreciate if you accept the answer.

    评论

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)