简体   繁体   中英

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.

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
  4. User edits the query and presses save
  5. Form submits (POST) to another PHP that validates and stores the new query
  6. PHP Script redirects to the query listing (full page reload)

What you will need:

  • JQuery + Colorbox (or comparable modal library)
  • the main page (where you would click edit)
  • an html form generated by php
  • php to handle the form post submission

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. If you want to control the size of the popup, it might be better to do the submit via JavaScript.

You'll need to use Javascript to open a new window that will contain the form. 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.

<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. This script should contain an HTML form that when submitted, will call an Update query on this ID variable. On completion, you can call another javascript function to close the edit window and refresh the content on the original calling page. Call this function via onLoad on the body of the script after the POST is process and the database updates.

                     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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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