简体   繁体   中英

how i can close popup window in php ...?

i have a page in where the different button available. on each button when a user click a popup window open. eg user click on ADD button and a popup window appear. user put some data in controls and press on save button. i want to close the open popup when user press on save and and data save successfully. im using this code to close the form

function closeForm() {
    echo "<script language=\"JavaScript\">\n";
    echo "function closeForm(){ \n";
    echo "window.self.close();";
    echo " } \n";
    echo "</script>\n";
    return true;
} 

this function call if the data successfully save.

any one help me to fix this problem...?

I beg your pardon but there is a way to do this in PHP via JS:

echo "<script type=\"text/javascript\" charset=\"utf-8\">window.self.close()</script>";

You can do this once all your PHP serverside processing is done.

There is no way to do it in PHP, use JavaScript instead. That's how your button should be coded in HTML:

<input type='button' value='Close' onclick='javascript: window.close();' />

Sir,

Your question is very vague, possibly mis-categorized and difficult to understand.

That being said, I will attempt to answer you, although, Algorithm first:

  1. You have a workflow process where users are entering data.
  2. You are guiding them through a series of steps, in which you are gathering different bits of information at each step.
  3. You need to capture the data at each of these steps from a "form" (HTML form, or Javascript Form) and then you need to successfully save the captured data.
  4. You need to supply the user with feedback on whether the operation was successful or not.
  5. After the form successfully saves You need to direct the user to another area.

Just to be crystal clear PHP is a server-side technology that has the ability to send dynamically generated HTML pages to a client's web browser, such as an HTML form, and to process the result of an HTML form that was "posted" back to it.

PHP also has the capability to do a SQL database "INSERT" to store your information, and then to subsequently evaluate the result of the database "INSERT" query.

The idea implied here is the user requests a page that contains a form where they can input data, (this form can just be one step in a series of steps...) the user then inputs their data and clicks the "next" or "submit" button in the form and their browser captures the input and sends it back to the server.

The server receives this information on a specific page (specified in the HTML form attribute "action") and has access to the sent data in one of several "super-global" PHP arrays ($_REQUEST[], $_GET[] or $_POST[], which is usually "$_POST" and is specified in the HTML form attribute "method").

The PHP script can then process the input: checking for XSS (cross site scripting), SQL Injection attacks, invalid input, etc. and if the input is valid execute a database insert query. After evaluating the result of that query and send an HTML "success/fail" page response back to the original user, or send the user the next HTML page (the next step in the process).

Javascript (like the code you supplied us with) is a client-side technology (client side ONLY!!!) that executes only in the end users web browser. Using a javascript form to capture user input (as in being able to hold it inside of persistent storage, like a database) defeats the purpose and usefulness of the well-known and "well-lit" path of using HTML forms to POST back to a PHP script/file/method... UNLESS you are talking about AJAX calls.

AJAX (Asynchronous JAvascript and XML) is not a new technology or another programming language rather it is using Javascript to make a "behind the scenes" call (on an independent "thread" on the client computer) to a specified PHP script/file/method to get a specific answer and then to insert the answer dynamically back into the current HTML DOM. (partial-page refresh, whole page DOES NOT refresh.) Then using Javascript forms to capture input could be interesting... although somewhat "off the beaten path", due to the fact that the user must have javascript enabled in their web browser in order for your site to function properly.

The code that you supplied us with indicates you are using javascript to close the entire web browser window, I'm confused...?

I would suggest investigating using Javascript/jQuery to change the "CSS visibility" attribute of an embedded HTML form, combined with some AJAX calls back to the server, instead of a pop-up of some kind, that way you could still use your "click button and input area appears" method, while still having a solid back-end infrastructure in place to handle input, processing and response.

Best of luck! :)

Set it as the click handler for the button.

Plain way:

<input id="save_button" type="button" onclick="closeForm();" value="Save"/>

jQuery way:

$("#save_button").click(closeForm);

Where you added the button of success just add a data-dismiss="modal" as a attribute like this:

'''

    <button type="button" class="btn btn-primary" onclick="saveNotes()" data- 
    dismiss="modal">Save changes</button>

'''

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