当action =“javascript:void(0)时提交表单

问题描述 投票:0回答:1

我有html步骤表单我需要在表单通过验证后提交表单并填写所有字段。我有一个动作控制器register.php但在我的html表单中我也有action =“javascript:void(0);”所以如何提交我的表格动作。

<div class="form-bottom">
  <div class="row">
    <div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
      <input type="text" class="form-control" placeholder="addres 1" id="add1" name="" value="" |>
    </div>
    <div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
      <input type="text" class="form-control" placeholder="address 2" id="add2" name="" value="">
    </div>
    <div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
      <input type="text" class="form-control" placeholder="city" id="city" name="" value="" |>
    </div>
  </div>
  <div class="row">
    <div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
      <input type="text" class="form-control" placeholder="Home Phone" id="contact_number" name="" value="">
    </div>
  </div>
  <div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
    <input type="checkbox" name="vehicle" value="Car" checked> I Agree<br>
  </div>
  <button type="button" class="btn btn-previous">Previous</button>
  <button type="submit" class="btn">Submit</button>
</div>
javascript html5 forms
1个回答
-1
投票

您可以使用ajax查询将数据发送到php脚本。

该代码插入onsubmit函数:

var formData = $(form_selector).serialize(); //Getting data from form
$.ajax({
    type: "POST", 
    url: URL to php script, 
    data: formData, 
    success: function(data) {
        //Action if data successfully sended, it's not nessesary 
    } 
});

您可以在https://api.jquery.com/Jquery.ajax上了解有关jQuery ajax的更多信息

© www.soinside.com 2019 - 2024. All rights reserved.