将变量传递到弹出框 [英] Passing variable to popup box
问题描述
关于在php中传递变量,我有一些复杂的问题.
i have a bit complicated problem about passing variables in php.
我已经在html <ul>
标记中列出并嵌套了项目,并且在每个项目附近我都有应该编辑目录或文件名的按钮(<ul>
列表是从服务器中现有的目录树视图生成的).
I have listed and nested items in html <ul>
tag and near every item i have button which should edit name of directory or file(<ul>
list are generated from existing directory tree view in server).
我设法制作了一个弹出表单,让用户输入新名称,并且我有指向旧名称的路径.
I managed to make a popup form to let user enter new name and i have path to the old name.
列出index.html(已生成)中的部分:
<ul>
<li>
<p>folder</p>
<div class="edit-button">
<a href="index.php?path=!working part with getting path!></a>
</div>
<ul>
<li>
... and here subfolders etc
</li>
</ul>
</li>
</ul>
index.html中的弹出表单部分:
<div id="popupEdit" class="popupEdit">
<?php $path = $_GET['path']; ?>
<div class="popupEdit-content">
<form action="rename.php" method="post">
<input type="text" name="path" value="<?php echo $path; ?>" >
<input type="text" name="new-name" placeholder="nowa nazwa">
<input type="submit" value="Submit" class="popupEdit-submit">
</form>
</div>
</div>
名称为path
的第一个输入将被隐藏以通过文件的路径.
rename.php
可以使用静态新名称正常工作,因此只需将new-name
传递到该文件中即可.
first input with name path
will be hidden to pass through path of the file.
rename.php
works fine with static new name so it's just about passing new-name
into that file.
所以这里有两个主要问题:
So there are two major problems here:
- 当我单击编辑按钮后打开弹出窗口时,我已经刷新了页面(由于
a
标签),所以我的弹出窗口不会持续很长时间,因为默认情况下(刷新后)弹出窗口具有display: none
- 在第一次单击按钮后,我没有将
path
属性添加到input
中,但是当网站的网址已经用?path=...
部分填充时,它很好,并且会弹出一半的时间(在重新加载之前)我能够看到名称为path
的输入正确填充了路径.
- when i open popup window after clicking in editing button i have refreshed page(because of
a
tag) so my popup dont last long because in default(after refresh) popup havedisplay: none
- after button is clicked for the first time i dont get
path
property intoinput
but when url of site is already filled with?path=...
part it's good and on popup for half of second(before it's reloaded) i am able to see that input with namepath
is filled with path correctly.
我认为使用ajax请求是可能的,但我不知道如何实现.
I think it's possible with ajax request but i have no idea how to making that possible.
我只想编辑当前节点名称,也许有一种更简单的方法?
I just want to edit current node name, maybe there is simplier way to do this?
推荐答案
我认为最好的选择是使用jQuery.这是一个有效的示例,可以动态设置表单的路径
I think the best option will be to use jQuery. Here's a working example, setting dynamically the path of the forms
$('.toggler').click(function(){
var path = $(this).attr('path');
$('#popupEdit').css('display','block');
$('.pathinput').val(path);
$('.path').text(path);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="toggler" path="example text">Click Me</button>
<button class="toggler" path="example text 2">Click Me 2</button>
<button class="toggler" path="example text 3">Click Me 2</button>
<div id="popupEdit" class="popupEdit" style="display: none">
<p class="path"></p>
<div class="popupEdit-content">
<form action="rename.php" method="post">
<input type="text" name="path" class="pathinput" value="PATHHERE" >
<input type="text" name="new-name" placeholder="nowa nazwa">
<input type="submit" value="Submit" class="popupEdit-submit">
</form>
</div>
</div>
这篇关于将变量传递到弹出框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!