I have created two pages – Contribute Page & Checkout Page.
On Contribute Page I have following code:
<?php
if(isset($_POST['submitnow'])) {
global $wpdb;
$wpdb->insert(
'wp9c_treetweet',
array(
'name' => $_POST['aname'],
'amt' => $_POST['aamt'],
'dept' => $_POST['adept']
),
array(
'%s',
'%d',
'%s'
)
);
}
?>
<form action="" method="POST" id="addcourse">
<label>Name:<input type="text" name="aname" size="30" required></label>
<label>Amount:<input type="text" name="aamt" size="30" required></label>
<label>Department:<input type="text" name="adept" size="30" required></label>
<input type="submit" name="submitnow" id="addcoursesubmit" value="Submit">
</form>
This code is working fine and is inserting the form data properly in database.
To redirect this page to Checkout Page I have added following code in functions.php:
function redirect_from_checkout() {
if( !isset( $_POST['submitnow'] ) )
return;
wp_redirect( home_url( '/checkout/' ) );
exit;
}
add_action( 'template_redirect', 'redirect_from_checkout' );
After adding redirect code in functions.php the redirection is working properly but the form data is not inserting into database table.
Plz help me out with a solution.