Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close Browser Tab After Submitting a Form?

Tags:

javascript

php

<?php
    /* ... SQL EXECUTION TO UPDATE DB ... */
?>

<form method  = "post"
      action  = "<?=$_SERVER['php_self']?>" 
      onSubmit= "window.close();">
  ...
  <input type="submit" value="submit" />
  <input type="reset"  value="reset" />
</form>

I would like to close page after submitting the form. After running the above code the page is closed after clicking submit button, but the SQL doesn't execute.

Can anyone help me?

like image 658
Acubi Avatar asked Sep 06 '25 12:09

Acubi


2 Answers

<?php    
    /* ... SQL EXECUTION TO UPDATE DB ... */

    echo "<script>window.close();</script>";
?>

and Remove the window.close() from the form onsubmit event

like image 61
Shakti Singh Avatar answered Sep 09 '25 07:09

Shakti Singh


Remove onsubmit from the form tag. Change this:

<input type="submit" value="submit" />

To:

<input type="submit" value="submit" name='btnSub' />

And write this:

if(isset($_POST['btnSub']))
    echo "<script>window.close();</script>";
like image 34
Sonal Khunt Avatar answered Sep 09 '25 06:09

Sonal Khunt