通过将其ID传递给模式框来向用户发送消息 [英] sending user a mesage by passing their id to a modal box

查看:71
本文介绍了通过将其ID传递给模式框来向用户发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过将用户名/id传递给模式进行识别,从而将消息形式创建为引导模式.

I am trying to create a message form into a bootstrap modal by Passing the user username/id to the modal for identification.

这是一个html/php代码,列出了注册用户.

here is an html/php code that made a list of registered users.

<div class="col-lg-4 col-md-4 col-sm-4 mb">
                            <div class="content" style="margin-bottom:5px;">
                            <ul class=" extended inbox">
                            <div class="notify-arrow notify-arrow-green"></div>
                            <li>
                                <p class="green">People you can follow</p>
                            </li>
                            <?php                
                            //Show all  users    
                             foreach ($users as $row) {
                            ?>
                            <li style="padding:3px; margin-bottom:3px; width:100%; background:#CF9;">
                                <a href="index.html#">
                                    <span class="photo" style="float:left; padding:4px;"><img alt="avatar" src="uploads/<?php echo $row['pix']; ?>" width="50" height="50"></span>
                                    <span class="subject" style="float:left;">
                                    <span class="from">
                                       <?php 
                                        echo '<a href="#">'.$row['user_lastname']. '&nbsp;'.$row['user_firstname'].'</a>';
                                        ?>  
<a class="" data-toggle="modal" data-target="#profile_pic_modal"><span class="glyphicon glyphicon-comment"></span></a>
                                       </span><br>
                                    <span class="time">
                                    <?php
                                    echo  (($row['receiver'] === $row['user_id'] && $row['sender'] === $user_id) 
                                     ? '<button class="btn follow following " rel="'.$row['user_id'].'">Following</button>'
                                     :' <button class="btn follow" rel="'.$row['user_id'].'">
                                        <i class="fa fa-user-plus alert-info"></i> Follow </button>');

                                       ?>
                                    </span>
                                    </span>

                                </a>
                            </li><br>

                            <?php
                             }
                             ?>
                            </ul>
                            </div>

当用户单击另一个用户的消息图标时,他/她应该能够发送消息.有人可以告诉我如何使用php/mysqli和ajax

When a user click on another user's message icon he/she should be able to send message. Could someone please show me how to do this using php/mysqli and ajax

推荐答案

首先添加如下所示的data-(anyName)标记

First add a data-(anyName) tag like below

<?php $ID = 'The persons Username'; ?>

    <a href='#' class='btn btn-warning btn-xs open-AddBookDialog' data-id='$ID' data-toggle='modal'>My Modal</a>

然后将一个输入标签放入您的模态主体中,其ID为example(MyID)

Then put a input tag inside your modal body with a ID of example(MyID)

<input type="text" id="MyID">

然后使用下面的代码(jquery),这会将data-id的值传递给模式展示中的输入标签.

Then using the code below (jquery) this will pass the value of data-id into that input tag on modal show.

$(document).on("click", ".open-AddBookDialog", function () {
     var myId = $(this).data('id');

     $(".modal-body #bMyID").val(myId);

      $('#myModal').modal('show');
});

这篇关于通过将其ID传递给模式框来向用户发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆