javascript - pass value from form to modal in php -
this question has answer here:
<a href="" data-toggle="modal" class="update_pic" data_id = "$id" data-target="#update-modal"><img height="100px" width="100px" src="data:image/jpeg;base64,'.base64_encode( $row['pestimage'] ).'"/><a/></td>'; echo"<td>$imagedesc $id</td>"; echo"<td>$pestname</td>"; echo"<td>$pesticide</td>"; echo"<td> <form action='editpest.php?id=$id' method='post'> <button data-toggle='modal' class='btn btn-primary btn-sm btn-block' data-target='#update-modal'>edit</button> <br/> <form action='../php/deletepest.php?id=$id' method='post'> <button class='btn btn-danger btn-sm btn-block'>delete</button> </form> </td>"; echo'</tr>'; <div id="update-modal" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h1 class="modal-title">update picture pest</h1> </div> <div class="modal-body"> <?php echo" <form action='../php/updateimage2.php?id=$id' method='post'>;"?> <div style="position:relative;"> <div class="input-group image-preview"> <input type="text" class="form-control image-preview-filename" disabled="disabled"> <!-- don't give name === doesn't send on post/get --> <span class="input-group-btn"> <!-- image-preview-clear button --> <button type="button" class="btn btn-default image-preview-clear" style="display:none;"> <span class="glyphicon glyphicon-remove"></span> clear </button> <!-- image-preview-input --> <div class="btn btn-default image-preview-input"> <span class="glyphicon glyphicon-folder-open"></span> <span class="image-preview-input-title">browse</span> <input type="file" accept="image/png, image/jpeg, image/gif" name="input-file-preview"/> <!-- rename --> </div> </span> </div> <br/> <br/> <div class="form-group"> <div class="col-lg-7 col-lg-offset-7.5"> <button type="submit" class="btn btn-primary btn-lg">update picture</button> </div> </div> </form>
hi want pass value of $id retrieved database modal, can use clause when update image.
this first question hope answer
<a href="" data-toggle="modal" class="update_pic" data_id = "$id" data-target="#update-modal"> <img height="100px" width="100px" src="data:image/jpeg;base64,'.base64_encode( $row['pestimage'] ).'"/> <a/> </td> <td><?php echo $imagedesc.''.$id;?></td> <td><?php echo $pestname;?></td> <td><?php echo $pesticide;?></td> <td> <a class='editclass' href="#form_modal" data-toggle="modal" data-id="<?echo $id;?>"> edit </a> <form action='../php/deletepest.php?id=$id' method='post'> <button class='btn btn-danger btn-sm btn-block'>delete</button> </form> </td> </tr>
js
<script> $('.editclass').click(function(){ var id=$(this).attr('data-id'); $.ajax({url:"editpest.php?id="+id,cache:false,success:function(result){ $(".modal-content").html(result); }}); }); </script>
footer (place code in footer or below <table></table>
)
<div class="modal fade" id="form_modal" tabindex="-1" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> </div> </div> </div>
editpest.php
<?php $id = $_get['id']; // now, write query here ?> <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">update</h4> </div> <div class="modal-body"> . . <?php echo "id: ".$id;?> . . // write code here update </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> </div>
Comments
Post a Comment