user3403327
user3403327

Reputation: 65

How to close window after PHP code is executed?

I have two problems:

  1. How do I close the window once I Have executed my PHP code which is a simple save textbox values to database?

  2. How do I get my text boxes to align so they perfectly aligned currently one is more indented than the other DEMO?

Here's the PHP code that saves data into my database once saved I want the current window to close:

<form name="Permit" id="Permit" action="<?php echo JURI::current(); ?>" method="post">
    Permit or Deny: <input align= center  type="text" name="Permit_or_Deny" value=""><br>
    Level <input type="text" name="Level" value=""><br>
    <p><input id="submit" name="submit" type="submit" value="Permit Or Deny Submit Buutton" /></p>
</form>
        
     
<?
if ((isset($_POST['Permit_or_Deny'])) || (isset($_POST['Level']))) {
    //first name or last name set, continue-->
    $Permit_or_Deny = $_POST['Permit_or_Deny'];
    $Level          = $_POST['Level'];
    
    $db =& JFactory::getDBO();
    $query = "INSERT INTO tp_newedit (Permit_or_Deny, Level) VALUES ('" . $Permit_or_Deny . "','" . $Level . "');";
    
    $db->setQuery($query);
    $db->query();
} else {
    echo '<h4>One Field Is Required!</h4>';
}
?>

Upvotes: 3

Views: 18532

Answers (2)

halkujabra
halkujabra

Reputation: 2942

For first part -

<form name="Permit" id="Permit" action="<?php echo JURI::current(); ?>" method="post">

    <div class="label" style="display:inline-block;width:200px"> Permit or Deny: </div><input align= center  type="text" name="Permit_or_Deny" value=""/><br>
        <div class="label" style="width:200px;display:inline-block;"> Level </div> <input type="text" name="Level" value=""><br>

        <p><input id="submit" name="submit" type="submit" value="Permit Or Deny Submit Buutton" /></p>
    </form>

For second part, place this on server side code-

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

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

Upvotes: 5

Ashoka Mondal
Ashoka Mondal

Reputation: 1171

Try window.close() of JavaScript:-

<?

if ((isset($_POST['Permit_or_Deny'])) || (isset($_POST['Level']))) {
    //first name or last name set, continue-->
    $Permit_or_Deny = $_POST['Permit_or_Deny'];
    $Level          = $_POST['Level'];

    $db =& JFactory::getDBO();
    $query = "INSERT INTO tp_newedit (Permit_or_Deny, Level) VALUES ('" . $Permit_or_Deny . "','" . $Level . "');";

    $db->setQuery($query);
    $db->query();

    echo  "<script type='text/javascript'>";
    echo "window.close();";
    echo "</script>";
} else {
    echo '<h4>One Field Is Required!</h4>';
}

?>

Upvotes: 4

Related Questions