-1

I have a form with a submit button. When i click this button i dont want to be redirected to the page connection.php, that is listed in action="". But insteed i want it to just show pop-up window that says successful or not successful, and let the connection2.php do its thing in the background.

HTML:

<form action="connection2.php" method="post">
                            <input type="date" name="date" placeholder="Name" required="">  
                            <input type="submit" name="submit" id="submit" class="strelka-send" value="Insert">
                            <div class="clear"> </div>
                        </form>

CONNECTION2.PHP:

<?php   
# Connection
$servername = ""; 
$connectionInfo = array(
"Database"=>"", 
"UID"=>"", 
"PWD"=>""
);
$conn = sqlsrv_connect($servername, $connectionInfo);
if( $conn === false ) {
    echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
    exit;
}

# Parameters
$Date = $_POST['date'];


$params = array 
(&$Date);

# Statement
$sql = "INSERT INTO table([Date]) VALUES 
(?)";
$stmt = sqlsrv_prepare($conn, $sql, $params);
if ($stmt === false) {
echo "Error (sqlsrv_prepare): ".print_r(sqlsrv_errors(), true);
exit;
}
if (sqlsrv_execute($stmt)) {
echo "Statement executed.\n";
} else {
echo "Error (sqlsrv_execute): ".print_r(sqlsrv_errors(), true);
}

# End
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
<!DOCTYPE html>
<html>
<body>
<br>
<h1>SUCCESS</h1>
<script>
setInterval(function(){ 
window.location.href="link_to_index.html" }, 5000);
</script>
</body>
</html>

So far i have set timer on the page connection2.php that opens after form is submited, and then goes back to previous page. But it is not the nicest solution.

ninja
  • 3
  • 3

2 Answers2

1

if you dont want redirection in form submit , you have to use AJAX technology for example JQUERY take a look at Submitting HTML form using Jquery AJAX

Netlog
  • 95
  • 8
0

Use this code to submit the form into a popup window.

This code submits the form to a popup window after its submission.

<form action="connection2.php" method="post" target="popupwindow" onsubmit="window.open('connection2.php', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true">

    <input type="date" name="date" placeholder="Name" required="">  
    <input type="submit" name="submit" id="submit" class="strelka-send" value="Insert">

</form>

I haven't tested this code.

But hoping that this will work for you.