How to save form data to database after submit
-
Hello!
Help please with save form data to database after submit.1. I created the shortcode with PayPal Form:
function checkout_shortcode ($atts){ ob_start(); global $wpdb; $current_user = wp_get_current_user(); echo "<div class='payform'> <form id='paymentForm' name='paymentForm' action='https://www.sandbox.paypal.com/cgi-bin/webscr' METHOD='POST'> <input type='hidden' name='action' value='save_sdb_checkout_shortcode' /> <input type='hidden' name='cmd' value='_xclick' /> <input type='hidden' name='business' value='[email protected]' /> <input type='hidden' id='item_number' name='item_number' value='1'> <input type='hidden' name='no_shipping' value='1'> <input type='hidden' name='return' value=https://site.com/return/ /> <input type='hidden' name='cancel_return' value=https://site.com/cancel/ /> <input type='hidden' name='notify_url' value=https://site.com/notify/ /> <label>Name:</label> <input type='text' name='name' value='".$current_user->display_name."'> <label>Email:</label> <input type='text' name='email' value='".$current_user->user_email."'> <label>Phone:</label> <input type='text' name='phone' value='".get_user_meta($user_id, 'phone', true)."'> <label>Pyment Purpose:</label> <input type='text' name='item_name'> <label>Payment Amount:</label> <input type='number' name='amount' min='0' max='100000' step='0.01'> <br><input type='submit' name='submit' value='Make a Payment' /> </form></div>"; $output = ob_get_clean(); return $output; }
2. After submit I need to save data to custom table:
global $wpdb; $payment_data = array(); $payment_data['user_id'] = get_current_user_id(); $payment_data['amount'] = $_POST['amount']; $payment_data['status'] = 'Pending'; $payment_data['payment_date'] = date('Y-m-d H:i:s'); $payment_data['payment_type'] = 'Paypal'; $payment_data['item_name'] = $_POST['item_name']; $wpdb->insert( $wpdb->get_blog_prefix() . 'payments', $payment_data );
But I cant understand how to do it.
I already tried many options(2 submits through js, Ajax) but no results (
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘How to save form data to database after submit’ is closed to new replies.