代码之家  ›  专栏  ›  技术社区  ›  jumps4fun

为什么这些几乎完全相同的HTML表单中只有一个对submit按钮单击做出反应?

  •  0
  • jumps4fun  · 技术社区  · 4 年前

    我有两种几乎相同的形式。一个用于编辑项目,另一个用于创建项目。由于某些原因,create表单对submit按钮的点击根本没有反应,而edit/update表单的工作与预期完全一致。我找不出这两者之间的任何差异,这应该导致这种行为。

    工作更新表:

    @extends ('layout')
    
    @section('middle-content')
    
        <div class="wrapper">
            <div id="page" class="container">
                <h4>Edit Competition Category</h4>
    
                <form method="POST" action="/competition-categories/{{$competitionCategory->id}}">
                    @csrf
                    @method('PUT')
    
                    <div class="form-group row">
                        <label for="competition-category-name-input" class="col-4 col-form-label">Name</label>
                        <div class="col-8">
                            <input id="competition-category-name-input" name="name" type="text" class="form-control" required="required" value="{{ $competitionCategory->name }}">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="competition-category-abbreviation-input" class="col-4 col-form-label">Abbreviation</label>
                        <div class="col-8">
                            <input id="competition-category-abbreviation-input" name="abbreviation" type="text" class="form-control" required="required" value="{{ $competitionCategory->abbreviation }}">
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="offset-4 col-8">
                            <button name="submit" type="submit" class="btn btn-primary">Submit</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    
    @endsection
    

    无响应创建表单:

    @extends ('layout')
    
    @section('middle-content')
    
        <div class="wrapper">
            <div id="page" class="container">
                <h4>New Competition Category</h4>
    
                <form method="POST" action="/competition-categories"></form>
                    @csrf
    
                    <div class="form-group row">
                        <label for="competition-category-name-input" class="col-4 col-form-label">Name</label>
                        <div class="col-8">
                            <input id="competition-category-name-input" name="name" type="text" class="form-control" required="required">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="competition-category-abbreviation-input" class="col-4 col-form-label">Abbreviation</label>
                        <div class="col-8">
                            <input id="competition-category-abbreviation-input" name="abbreviation" type="text" class="form-control" required="required">
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="offset-4 col-8">
                            <button name="submit" type="submit" class="btn btn-primary">Submit</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    
    @endsection
    
    0 回复  |  直到 4 年前
        1
  •  2
  •   Dynamite    4 年前

    这条线: <form method="POST" action="/competition-categories"></form> 您的非工作表,请删除 </form> 你开始了又关闭了这就是原因。