笑故挽风 2017-06-07 11:45 采纳率: 100%
浏览 12

表单URL更改数据POST

I have a URL:

http://domanin.com/search-result/?start=06%2F08%2F2017&end=06%2F09%2F2017&room_num_search=1&adult_number=1&children_num=0

And I have a Bootstrap form:

<form class="form-inline search-hotel-box">
  <div class="form-group">
    <label><span class="flaticon-time"></span></label>
    <input type="text" class="form-control" id="checkin" placeholder="Check In" value="">
  </div>
  <div class="form-group">
    <input type="text" class="form-control" id="checkout" placeholder="Check Out" value="">
  </div>
  <div class="form-group">
    <label><span class="flaticon-door-key"></span></label>
    <select class="form-control">
    <option disabled selected>Rooms</option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
  </select>
    <i class="fa fa-angle-down"></i>
  </div>
  <div class="form-group">
    <label><span class="flaticon-profile-1"></span></label>
    <select class="form-control">
    <option disabled selected>Adults</option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
  </select>
    <i class="fa fa-angle-down"></i>
  </div>
  <button type="submit" class="btn btn-default">Search Hotel</button>
</form>

How can I make a POST to that URL, changing the data of the URL? I don't know how it could be if I used PHP, or is it possible to use jQuery to do this? Would appreciate any help with this.

  • 写回答

1条回答 默认 最新

  • weixin_33749131 2017-06-07 12:03
    关注

    So if you want to POST data to a particular webpage then you can do this using action and method attribute of form element as:

    <form class="form-inline search-hotel-box" action="http://domanin.com/search-result/demo.php" method="POST">
    

    You also need to provide name to all the different form fields as:

    <input type="text" name="start" class="form-control" id="checkin" placeholder="Check In" value="">
    
    <input type="text" name="end" class="form-control" id="checkout" placeholder="Check Out" value="">
    
    <select class="form-control" name="room_no_search">
    
    <select class="form-control" name="adult_no">
    

    Now when anyone fills all the info and clicks submit then all the data will be posted to the URL that is provided in the action attribute. If you want to sent data by appending in URL then use GET instead of POST.

    The data which is sent can be easily retrieved using php as follows:

    $var = $_GET['start'];
    

    or

    $var = $_POST['start'];
    
    评论

报告相同问题?