简体   繁体   中英

how can i send parameters with <a> for set query MySQL in smarty & Php

i want create grid with bootstrap in smarty / php
in grid i have name, family, ... & edit button .
when i click in btn edit, modal popup open, but i don't know how sent record ID to function for set query & show in modal:
sample code:
www.bootply.com/webdeveloper/iQrK1Yxlkk

btn:

<a href="" class="btn btn-success" data-toggle="modal" data-target="#myModal" data-backdrop="static">
  Edit User
</a>

Modal:

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        username: ...
        <br>
        Password: ...
        <br>
        avatar: ...
        <br>
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

The simpliest solution:

  • remove attributes data-toggle="modal" and data-target="#myModal"
  • Add data-id attribute for tag a
  • Add bind jquery to click for tag a
  • when user click to tag a:
    • Insert record ID into hidden text input in modal form
    • Run bootstrap modal manually $('#myModal').modal()

Hope it will help

EDIT:

Also in documentation i see special event when modal run (probably it is more bootstrap.js way...):

$('#myModal').on('show.bs.modal', function (e) {
   // get record ID here
})

so you can use e.target to get attributes of tag a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM