为什么我的提交按钮不起作用?

时间:2015-08-04 03:24:01

标签: javascript php jquery html forms

当用户点击模式时,表单可用。当我单击模态中的提交按钮时,它按钮不起作用。

foreach ($posts as $post) { echo '
    <td>
      <button type="button" class="btn btn-success" data-toggle="modal" data-target="#$id_user">Validasi</button>
    </td>
  </tr>
</tbody>
';
}

这是模式:

echo '
<div id="$id_user" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content" id="registerContent">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <div class="modal-text-header text-center">Validasi</div>
      </div>
      <div class="modal-body">
        <div class="container-fluid">'; echo '
          <form class="form col-md-12 center-block" action="http://localhost/MMM/admin/validasi/'.$id_user.'" method="POST" enctype=\ "multipart/form-data\">
            <div class="form-group">
              <input class="form-control input" placeholder="Dana awal (RP.1.000.000,-)" type="text" name="dana">
            </div>
            <div class="form-group">
              <input type="submit" class="btn btn-primary btn btn-block" name="submit" value="Submit">
            </div>
          </form>
        </div>
      </div>
      <div class="modal-footer">
        <div class="col-md-12">
          <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
        </div>
      </div>
    </div>
  </div>
</div>' ;

3 个答案:

答案 0 :(得分:0)

您需要检查提交按钮是否已通过,然后运行代码。这将确保您不会收到未定义的索引错误。

if (isset($_POST['submit'])) {
 // Your code here.
}

还可以使用表单(<form></form>)标记在method="post"中指定POST请求。

答案 1 :(得分:0)

不要在单引号中使用echo:这就是令你头疼的问题。创建如下代码:

<div id="<?php echo $id_user ?>" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content" id="registerContent">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
        <div class="modal-text-header text-center">Validasi</div>
      </div>
      <div class="modal-body">
        <div class="container-fluid">
          <form class="form col-md-12 center-block" action="http://localhost/MMM/admin/validasi/<?php echo $id_user ?>" method="POST" enctype="multipart/form-data">
            <div class="form-group">
              <input class="form-control input" placeholder="Dana awal (RP.1.000.000,-)" type="text" name="dana">
            </div>
            <div class="form-group">
              <input type="submit" class="btn btn-primary btn btn-block" name="submit" value="Submit">
            </div>
          </form>
        </div>
      </div>
      <div class="modal-footer">
        <div class="col-md-12">
          <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
        </div>
      </div>
    </div>
  </div>
</div>

和其他代码:

<?php 
foreach ($posts as $post): ?>
<td>
  <button type="button" class="btn btn-success" data-toggle="modal" data-target="#$id_user">Validasi</button>
</td>
<?php endforeach; ?>

另请阅读What is the difference between single-quoted and double-quoted strings in PHP?

答案 2 :(得分:0)

错误

  1. 错误放置<form>打开和关闭
  2. enctype=\ "multipart/form-data\",(\)中的匹配不匹配字符。
  3. 所以最终的Well-Form代码

    <div id="$id_user" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content" id="registerContent">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <div class="modal-text-header text-center">Validasi</div>
                </div>
                <form class="form col-md-12 center-block" action="http://localhost/MMM/admin/validasi/'.$id_user.'" method="POST" enctype="multipart/form-data">
                    <div class="modal-body">
                        <div class="container-fluid">
                            <div class="form-group">
                                <input class="form-control input" placeholder="Dana awal (RP.1.000.000,-)" type="text" name="dana">
                            </div>
                            <div class="form-group">
                                **
                                <input type="submit" class="btn btn-primary btn btn-block" name="submit" value="Submit">**
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <div class="col-md-12">
                            <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    

    注意:您没有在表单中上传任何Files。所以不要使用enctype