按钮不响应laravel

时间:2019-01-31 08:31:59

标签: laravel laravel-routing laravel-5.7 laravel-form

我在此页面上有动作网址相同的表格。我的第二个表格工作得很好,但是当我按下按钮或<a>时,mu的第一个表格没有响应。我尝试在表单之间切换<form action="{{url('purchase')}}" method="post"),我尝试在第二种表单上剪切动作,然后将其移至第一种表单,但还是没有运气...知道吗?这是我的代码的总和

    <form class="px-2 py-2" action="{{ url('purchase') }}" method="post">
        {{csrf_field()}}
        <div id="items">
        </div>
        <div class="row mx-1 px-2">
            <a href="#" class="btn btn-primary">Purchase</a>
        </div>
    </form>

这是我的第一个表单,在id="items"内是空的,因为我用javascript填充了它

<form id="newItemForm" style="display:none;">
  <div class="form-group row"  id="item">
    <label for="invoice" class="col-sm-2 col-form-label">Supplier</label>
    <div class="col-sm-2">
      <select class="form-control" onchange="newExisting(this)">
        <option value="#" selected>Choose Supplier</option>
        <option value="existing">Existing Supplier</option>
        <option value="new">New Supplier</option>
      </select>
    </div>
    <div class="col-sm-8" id="existingCompany" style="display:none;">
      <div class="row">
        <div class="col-sm-4">
          <select class="form-control" name="fromE" onchange="localImport(this)">
            <option value="#" checked>From</option>
            <option value="f" checked>Import</option>
            <option value="l" checked>Local</option>
          </select>
        </div>
        <div class="col-sm-8">
          <select class="form-control" name="supplier" id="supplierID">
            <option value="#">Choose Company</option>
          </select>
        </div>
      </div>
    </div>
    <div class="col-sm-8" style="display:none;" id="newCompany">
      <div class="row">
        <div class="col-sm-4">
          <select class="form-control" name="fromN">
            <option value="#" checked>From</option>
            <option value="f" checked>Import</option>
            <option value="l" checked>Local</option>
          </select>
        </div>
        <div class="col-sm-4">
          <input type="text" name="kind" value="" placeholder="PT, CV, FIRMA" class="form-control">
        </div>
        <div class="col-sm-4">
          <input type="text" name="supplierName" placeholder="Company Name" class="form-control">
        </div>
      </div>
    </div>
  </div>
    <div id="newItems">
      <div class="form-group row"  id="item">
        <label for="invoice" class="col-sm-2 col-form-label">Item Name</label>
        <div class="col-sm-10">
          <input type="text" name="item0" class="form-control" placeholder="Item Name" onkeyup="getCompanyGoods(this)">
          <span class="text text-danger" style="display:none;" id="existsWarning0">*Item already exists</span>
        </div>
      </div>
      <div class="form-row">
        <div class="form-group col-md-3">
          <label for="taxInvoice">QTY<span class="text-danger">*</span></label>
          <input type="number" name="qty0" class="form-control" id="qty0" required onkeyup="calculate(this)">
        </div>
        <div class="form-group col-md-3">
          <label for="inputPassword4">Units<span class="text-danger">*</span></label>
          <input type="number" name="units0" class="form-control" id="units0" required onkeyup="calculate(this)">
        </div>
        <div class="form-group col-md-3">
          <label for="inputPassword4">Total</label>
          <div class="form-controll font-weight-bold" style="font-size:x-large;" id="total0">IDR0.00</div>
        </div>
      </div>
    </div>
    <label class="btn btn-primary" id="newRow" onclick="addRow()">+ Item</label>
    <input type="hidden" name="type" value="new">
    <input type="hidden" name="nore" value="#" id="nore">
    <input type="number" name="totalItem" value="0" id="totalItem">
    <button name="button" class="btn btn-danger float-right" >Purchase</button>
  </form>

这是我的第二种形式,它可以正常工作。...

2 个答案:

答案 0 :(得分:1)

更改

<a href="#" class="btn btn-primary">Purchase</a> 

<button type='submit'>Purchase</button>

答案 1 :(得分:0)

因为您使用的是标签,而不是按钮类型“提交”

<a href="#" class="btn btn-primary">Purchase</a>

将其更改为这样

<button class="btn btn-primary" type="submit"> Purchase </button>