简体   繁体   English

弹出PHP表单

[英]Pop-Up PHP form

I've seen this done before on website, and I'm wondering how I would go about doing this. 我以前在网站上已经看到过此操作,并且想知道如何进行此操作。 I'm trying to pop up an edit form on a database query site where on clicking the button, I would pass a var through $_POST to a php page, and have that php page be the pop-up such that the user can use the form contained within that php page to edit the details of that database entry. 我试图在数据库查询站点上弹出一个编辑表单,在该站点上单击按钮,我将通过$ _POST将var传递给php页面,并让该php页面成为弹出窗口,以便用户可以使用该php页面中包含的表单,用于编辑该数据库条目的详细信息。

Any help structuring this would be appreciated. 任何帮助构建这一点的方法将不胜感激。 Thanks!! 谢谢!!

Workflow: 工作流程:

  1. User navigates to the query listing in the browser 用户导航到浏览器中的查询列表
  2. User clicks edit (colorbox enabled link) 用户点击修改(启用了启用颜色框的链接)
  3. GET request is sent to a PHP script that returns a query editing form based on a $_GET param GET请求发送到PHP脚本,该脚本返回基于$ _GET参数的查询编辑表单
  4. User edits the query and presses save 用户编辑查询并按保存
  5. Form submits (POST) to another PHP that validates and stores the new query 表单提交(POST)到另一个验证并存储新查询的PHP
  6. PHP Script redirects to the query listing (full page reload) PHP脚本重定向到查询列表(重新加载整个页面)

What you will need: 您将需要什么:

  • JQuery + Colorbox (or comparable modal library) jQuery + Colorbox(或类似的模式库)
  • the main page (where you would click edit) 主页(您将在其中单击编辑)
  • an html form generated by php 由php生成的html表单
  • php to handle the form post submission php处理表单提交

Older versions of HTML (like 4.0) allow a target attribute on the form tag, so you can just have the form submit via post to the action url and then put target="_blank" or whatever in the form tag as well. 较旧的HTML版本(例如4.0)在form标记上提供了target属性,因此您可以通过发布将表单通过post提交到操作url,然后将target =“ _ blank”或任何形式放入form标记。 If you want to control the size of the popup, it might be better to do the submit via JavaScript. 如果您想控制弹出窗口的大小,最好通过JavaScript进行提交。

You'll need to use Javascript to open a new window that will contain the form. 您将需要使用Javascript打开一个包含表单的新窗口。 A simple function such as the one that follows would work: 一个简单的函数(例如下面的函数)将起作用:

function openWindow(theURL,winName,features) { window.open(theURL,winName,features); }

Next to the database row to be edited in your front end, you could add an edit link that calls this function and opens a new script that will accept the row id through a GET variable and use that to present a form for editing. 在前端要编辑的数据库行旁边,您可以添加一个调用此函数的编辑链接,并打开一个新脚本,该脚本将通过GET变量接受行ID,并使用该脚本来呈现要编辑的表单。

<a href=\"javascript:openWindow('item_add.php?id=1','','width=500,height=300');\">

Item_add php should accept the id variable from the GET array. PHP的Item_add应该接受GET数组中的id变量。 This script should contain an HTML form that when submitted, will call an Update query on this ID variable. 该脚本应包含一个HTML表单,提交后将对该ID变量调用Update查询。 On completion, you can call another javascript function to close the edit window and refresh the content on the original calling page. 完成后,您可以调用另一个javascript函数以关闭编辑窗口并刷新原始调用页面上的内容。 Call this function via onLoad on the body of the script after the POST is process and the database updates. 在POST处理和数据库更新之后,通过脚本主体上的onLoad调用此函数。

                     function redirect_to(where, closewin)
                 {
                         opener.location= 'index.php?' + where;

                         if (closewin == 1)
                         {
                                 self.close();
                         }
                 }

<body onload="redirect_to('index.php','1')">

This is just the technique I have used previously, but depending on your context you may want to look into some AJAX solutions. 这只是我以前使用的技术,但是根据您的上下文,您可能需要研究一些AJAX解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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