单击链接时如何将编辑表单显示为 jquery 弹出模式

发布于 2024-12-17 22:07:33 字数 3654 浏览 2 评论 0原文

我正在视图文件中显示数据库中的信息,并且有一个编辑选项,但尚未起作用。我想要这样的编辑选项 - 当任何用户单击编辑链接(我使用图像作为编辑按钮)时,将弹出一个 jquery 模式并显示一个简单的编辑表单(并且在后台它将生成一个根据点击的值查询数据库信息)。

请您帮助我如何从数据库中获取数据并在单击编辑链接时将编辑表单显示为 jquery 弹出模式? (请检查下面的视图文件以查看编辑链接)

至少有一个示例将不胜感激:)

提前致谢:)

这是我的视图文件:

 <article id="dashboard">

            <?php if(count($records) > 0) { ?>
            <h1> Batch Name: <?php echo "$batchname";?> </h1>
            <table id="table1" class="gtable sortable">
            <thead>
                    <tr>
                        <th>S.N</th>
                        <th>Student ID</th>
                        <th>Exam Date</th>
                        <th>Exam Type</th>
                        <th>Subject</th>
                        <th>Total Mark</th>
                        <th>Highest Mark</th>
                        <th>Obtained Mark</th>
                        <th>GPA</th>
                        <th>Grade</th>
                        <th>Status</th>
                        <th>Edit/Delete</th>
                    </tr>
            </thead>
            <tbody>
             <?php $i = $this->uri->segment(3) + 0; foreach ($records as $row){ $i++; ?>


                    <tr>
                        <td><?php echo $i; ?>.</td>

                        <td><a href="<?php echo base_url(); ?>viewbatch/get/<?php echo $row['studentid']; ?>"><?php echo $row['studentid'];?></a></td>
                        <td><?php echo $row['examdate'];?></td>
                        <td><?php echo $row['examtype'];?></td>

                        <td><?php echo $row['subject'];?></td>
                        <td><?php echo $row['totalmark'];?></td>

                        <td><?php echo $row['highestmark'];?></td>
                        <td><?php echo $row['obtainedmark'];?></td>

                        <td><?php echo $row['gradepoint'];?></td>
                        <td><?php echo $row['grade'];?></td>
                        <td><?php echo $row['status'];?></td>

                        <td> <a href="<?php echo base_url(); ?>updatebatch/get/<?php echo $row['id']; ?>" title="Edit"><img src="<?php echo base_url(); ?>support/images/icons/edit.png" alt="Edit" /></a>
                             <a href="#" title="Delete"><img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" /></a>
                             </td>
                    </tr>
            <?php  } ?>

            </tbody>
            </table>
            <?php } else { echo "No Record Found";} ?>
            <div class="tablefooter clearfix">

                        <div class="pagination">
                        <?php echo $this->pagination->create_links(); ?> 
                        </div>
            </div>



        </article>

编辑::

谢谢 mmmshuddup 的帮助。实际上,我的目的是展示一个jquery弹出模态表单,用户可以通过该表单更新数据。目前,在视图文件中,我有一个从数据库检索的学生信息列表。为了让用户更新学生信息,我有一个编辑选项,但目前它不处于工作模式。到目前为止,您的回复已经足够好了,但是请您告诉我如何在 之间以模态形式显示数据。您不必提及有关控制器部分的任何内容,假设我将“id”发布到我的控制器,然后查询数据库并将数据发送回以常规方式查看文件。现在我只想知道如何向我的用户呈现“更新”表单(已经向用户填写了相关信息)。

I am displaying information from database in a view file and there is an option to edit but its not functional yet. I want to have the edit option like this- when any user clicks on the the edit link(I am using an image as edit button) a jquery modal will pop up and show a simple edit form (and in the background it will make a query to database for information based on the clicked value).

Would you please kindly help me how to fetch the data from database and show an edit form as a jquery pop up modal when clicked on the edit link? (Please check the view file below to see the edit link)

At least an example would be highly appreciated :)

Thanks in Advance :)

Here's my View file:

 <article id="dashboard">

            <?php if(count($records) > 0) { ?>
            <h1> Batch Name: <?php echo "$batchname";?> </h1>
            <table id="table1" class="gtable sortable">
            <thead>
                    <tr>
                        <th>S.N</th>
                        <th>Student ID</th>
                        <th>Exam Date</th>
                        <th>Exam Type</th>
                        <th>Subject</th>
                        <th>Total Mark</th>
                        <th>Highest Mark</th>
                        <th>Obtained Mark</th>
                        <th>GPA</th>
                        <th>Grade</th>
                        <th>Status</th>
                        <th>Edit/Delete</th>
                    </tr>
            </thead>
            <tbody>
             <?php $i = $this->uri->segment(3) + 0; foreach ($records as $row){ $i++; ?>


                    <tr>
                        <td><?php echo $i; ?>.</td>

                        <td><a href="<?php echo base_url(); ?>viewbatch/get/<?php echo $row['studentid']; ?>"><?php echo $row['studentid'];?></a></td>
                        <td><?php echo $row['examdate'];?></td>
                        <td><?php echo $row['examtype'];?></td>

                        <td><?php echo $row['subject'];?></td>
                        <td><?php echo $row['totalmark'];?></td>

                        <td><?php echo $row['highestmark'];?></td>
                        <td><?php echo $row['obtainedmark'];?></td>

                        <td><?php echo $row['gradepoint'];?></td>
                        <td><?php echo $row['grade'];?></td>
                        <td><?php echo $row['status'];?></td>

                        <td> <a href="<?php echo base_url(); ?>updatebatch/get/<?php echo $row['id']; ?>" title="Edit"><img src="<?php echo base_url(); ?>support/images/icons/edit.png" alt="Edit" /></a>
                             <a href="#" title="Delete"><img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" /></a>
                             </td>
                    </tr>
            <?php  } ?>

            </tbody>
            </table>
            <?php } else { echo "No Record Found";} ?>
            <div class="tablefooter clearfix">

                        <div class="pagination">
                        <?php echo $this->pagination->create_links(); ?> 
                        </div>
            </div>



        </article>

Edit::

Thank you mmmshuddup for your help.Actually I am aiming to show a jquery pop up modal form through which users can update data. At present in the view file I have a list of students information which I have retrieved from database. In order to let users update student information I have an edit option but at present its not in working mode. So far what you have replied is good enough but would you please kindly show me how to display data in the modal form, in between . You don't have to mention anything about the controller part, lets say I am posting the "id" to my controller and then quering the database and sending back the data to view file in a regular way. Now all I just want to know how to present the "update" form (already filled with relevant information to the user) to my user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难遇 2024-12-24 22:07:33

首先,您需要向编辑锚标记添加 class 和/或 id 属性。

像这样的事情:

<a href="<?= base_url(); ?>updatebatch/get/<?= $row['id']; ?>" title="Edit"
    id="edit-<?= $row['id']; ?>" class="edit-link">
    <img src="<?= base_url(); ?>support/images/icons/edit.png" alt="Edit" /></a>

接下来,创建一个 div 来加载模态内容:

<div id="modal-dialog"></div>

现在,您已经准备好设置 jquery 模态内容和 onclick 事件侦听器编辑链接:

$('#modal-dialog').dialog({
    title: 'Edit Your Item',
    autoOpen: false,
    show: 'blind',
    width: 800,
    height: 600,
    modal: true
});

var baseUrl = "<?= base_url(); ?>updatebatch/get/";

$('.edit-link').click(function(e) {
    var id = this.id.split('-')[1];
    $('#dialog')
        .load(baseUrl + id) // or something like this
        .dialog('open');
});

同样,这只是您可以如何执行此操作的示例。还有其他方法可以动态加载内容。我不确定您到底希望 PHP 脚本做什么。

编辑:

根据 OP 的请求,这里是如何使用 PHP 填写字段的示例(不是 JavaScript):

<!-- assume $row is the query result array of data -->
<input type="hidden" name="id" value="<?php echo $row['id'];" />
<input type="text" name="name" id="name" value="<?php echo $row['name']; ?>" />
<textarea name="content" id="content" rows="8" cols="50">
    <?php echo $row['content']; ?>
</textarea>

First of all, you're going to want to add a class and/or id attribute to your edit anchor tags.

Something like this:

<a href="<?= base_url(); ?>updatebatch/get/<?= $row['id']; ?>" title="Edit"
    id="edit-<?= $row['id']; ?>" class="edit-link">
    <img src="<?= base_url(); ?>support/images/icons/edit.png" alt="Edit" /></a>

Next, create a div in which to load your modal content:

<div id="modal-dialog"></div>

Now, you're ready to set up your jquery modal stuff and the onclick event listeners for the edit link:

$('#modal-dialog').dialog({
    title: 'Edit Your Item',
    autoOpen: false,
    show: 'blind',
    width: 800,
    height: 600,
    modal: true
});

var baseUrl = "<?= base_url(); ?>updatebatch/get/";

$('.edit-link').click(function(e) {
    var id = this.id.split('-')[1];
    $('#dialog')
        .load(baseUrl + id) // or something like this
        .dialog('open');
});

Again, this is just an example of how you could do it. There are other ways to dynamically load content. And I'm not sure what exactly you want your PHP script to do..

Edit:

Per OP's request, here is an example of how to fill in fields using PHP (not javascript):

<!-- assume $row is the query result array of data -->
<input type="hidden" name="id" value="<?php echo $row['id'];" />
<input type="text" name="name" id="name" value="<?php echo $row['name']; ?>" />
<textarea name="content" id="content" rows="8" cols="50">
    <?php echo $row['content']; ?>
</textarea>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文