表单提交未按预期工作

时间:2018-01-20 15:52:01

标签: php mysql

我正在尝试提交以下表单,但无法正常工作:

<form action="venues.php" id="filterform" method="post" name="filterform">
    <label class="custom-control custom-checkbox">
        <input class="custom-control-input" name="Alfresco" type="checkbox">
        <span class="custom-control-indicator"></span>
        <span class="custom-control-description">Alfresco</span>
    </label>
    <label class="custom-control custom-checkbox">
        <input class="custom-control-input" name="WaterFront" type="checkbox">
        <span class="custom-control-indicator"></span>
        <span class="custom-control-description">WaterFront</span>
    </label>
    <label class="custom-control custom-checkbox">
        <input class="custom-control-input" name="Nature" type="checkbox">
        <span class="custom-control-indicator"></span>
        <span class="custom-control-description">Nature</span>
    </label>
    <label class="custom-control custom-checkbox">
        <input class="custom-control-input" name="Classy" type="checkbox">
        <span class="custom-control-indicator"></span>
        <span class="custom-control-description">Classy</span>
    </label>
</form>

以下是我用来处理表单提交的PHP代码:

if ( isset( $_POST["Alfresco"] ) ) {
    $query = 'SELECT venue_name, picture, price, capacity
        FROM venues
        WHERE theme = "Alfresco"
        LIMIT ' . $start_from . ' , ' . $items_page . ' ; ';
    $result = $con->query( $query );
    $num_results = $result->num_rows;
    // etc.
}

我做错了什么,如何让它发挥作用?

我似乎在复选框方面遇到问题,因为其他带有type文字的输入字段效果很好。

我有提交按钮。

       <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    <button type="submit" class="btn btn-primary" name="submitForm" form="filterform" value="submitForm" id="submitForm">Filter</button>
  </div> 
</form>

1 个答案:

答案 0 :(得分:0)

没有提交按钮或提交表单的javascript,因此php永远不会被执行

尝试在表单中添加<input type="submit">

如果您希望在单击复选框后立即执行php,则需要使用一些javascript告诉浏览器在输入字段上单击时提交表单。