From: Anthony Talarico Date: Tue, 24 Jan 2017 13:28:41 +0000 (-0500) Subject: adding session data to preserve form input in the event of a submission error. X-Git-Tag: v1.0.6^2~3 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=f2b74a039f02eacd1a5488a25283a05daf86979e;p=WP-Plugins%2FGlmPayments.git adding session data to preserve form input in the event of a submission error. --- diff --git a/includes/payment-display.php b/includes/payment-display.php index 8434b61..08f32b2 100755 --- a/includes/payment-display.php +++ b/includes/payment-display.php @@ -8,8 +8,10 @@ * */ global $wpdb; +echo $_REQUEST['first_name']; +$out1 = ob_get_contents(); if(isset($_REQUEST['action'])) -{ +{ if($_REQUEST['action']=='submitpayment') { // Check the form for reCaptcha @@ -27,14 +29,27 @@ if(isset($_REQUEST['action'])) ), 'cookies' => array() ) ); + $response_code = wp_remote_retrieve_response_code( $response ); $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); if ( $api_response['success'] != true ) { + + get_form_input(); $_SESSION['payment_msg'] = 'Captcha did not verify!'; + header("Location:".site_url().$_SERVER['REQUEST_URI']); exit; + } else { + + $_SESSION['payment_msg'] = 'Captcha did not verify!'; + foreach($_SESSION as $key => $val){ + if ($key !== 'payment_msg'){ + unset($_SESSION[$key]); + } + } } - $first_name = $_REQUEST['first_name']; + + $first_name = (isset($_REQUEST['first_name'])) ? $_REQUEST['first_name'] : ''; $last_name = $_REQUEST['last_name']; $organization = $_REQUEST['organization']; $address = $_REQUEST['address']; @@ -48,7 +63,7 @@ if(isset($_REQUEST['action'])) $r_frequency = $_REQUEST['r_frequency']; $r_times = $_REQUEST['r_times']; $amount = $_REQUEST['amount']; - $invoice_num = $_REQUEST['invoice_num']; + $invoice_num = $_REQUEST['invoice_num']; $card_type = $_REQUEST['card_type']; $x_card_num = $_REQUEST['x_card_num']; $exp_month = $_REQUEST['exp_month']; @@ -59,7 +74,7 @@ if(isset($_REQUEST['action'])) // Adjust this to point to the Authorize.Net PHP SDK include dirname(__FILE__) .'/../anet_php_sdk/AuthorizeNet.php'; - + $METHOD_TO_USE = "AIM"; $mysetting = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."payment_setting" ); define("AUTHORIZENET_API_LOGIN_ID",$mysetting[0]->api_login); // Add your API LOGIN ID @@ -106,7 +121,7 @@ if(isset($_REQUEST['action'])) } else { - // wp_mail( 'anthony@localhost', 'test1c', 'pass'); + get_form_input(); header("Location:".site_url().$_SERVER['REQUEST_URI']); exit; } @@ -117,7 +132,7 @@ if(isset($_REQUEST['action'])) function glm_payment_form() { wp_enqueue_script('reCaptcha', 'https://www.google.com/recaptcha/api.js'); ob_start(); - global $wpdb; + global $wpdb; ?>
@@ -141,31 +156,31 @@ function glm_payment_form() { First name* - + Last name* - + Organization - + Address* - + City* - + @@ -426,76 +441,76 @@ function glm_payment_form() { Zip* - + Phone - + Email* - + @@ -507,7 +522,7 @@ function glm_payment_form() { Amount* $
- +
@@ -515,7 +530,7 @@ function glm_payment_form() { Invoice Number - + @@ -523,16 +538,16 @@ function glm_payment_form() { Card type* Credit Card Number* - + @@ -540,23 +555,23 @@ function glm_payment_form() { / @@ -565,7 +580,7 @@ function glm_payment_form() { Card (CVV) Code* - + @@ -573,7 +588,7 @@ function glm_payment_form() { Comment - + @@ -1217,11 +1232,6 @@ function glm_payment_form() { return ; } - - - - - var paymentMethod = ""; paymentMethod = "os_authnet"; @@ -1424,7 +1434,8 @@ function glm_payment_form() { diff --git a/includes/payment-function.php b/includes/payment-function.php index 4b8914b..665cac4 100755 --- a/includes/payment-function.php +++ b/includes/payment-function.php @@ -7,7 +7,7 @@ function authorizepayment($METHOD_TO_USE,$REQUEST,$address1='',$city='',$state=' } else if (!checkCreditCard($REQUEST['x_card_num'], $REQUEST['card_type'], $ccerror, $ccerrortext)) { - $_SESSION['payment_msg'] = 'Please enter a valid credit card number.'; + $_SESSION['payment_msg'] = 'Please ensure the credit card number, CVV code and expiration date are correct'; return false; } else @@ -40,7 +40,6 @@ function authorizepayment($METHOD_TO_USE,$REQUEST,$address1='',$city='',$state=' } else { - //echo "1"; $_SESSION['payment_msg'] = $response->response_reason_text; } } @@ -54,8 +53,7 @@ function authorizepayment($METHOD_TO_USE,$REQUEST,$address1='',$city='',$state=' // Transaction approved! Do your logic here. // Redirect the user back to your site. //$return_url = $site_root . 'thank_you_page.php?transaction_id=' .$response->transaction_id; - //echo "2"; - paymentemail(); + paymentemail(); return true; } @@ -64,7 +62,7 @@ function authorizepayment($METHOD_TO_USE,$REQUEST,$address1='',$city='',$state=' // There was a problem. Do your logic here. // Redirect the user back to your site. $_SESSION['payment_msg'] = $response->response_reason_text; - // echo "3"; + header("Location:".site_url().$_SERVER['REQUEST_URI']); exit; @@ -73,7 +71,6 @@ function authorizepayment($METHOD_TO_USE,$REQUEST,$address1='',$city='',$state=' } else { - //echo "4"; $_SESSION['payment_msg'] = "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in"; } } @@ -282,5 +279,25 @@ function checkCreditCard($cardnumber, $cardname, &$errornumber, &$errortext) { // The credit card is in the required format. return true; } - +function get_form_input(){ + $_SESSION['first_name'] = (isset($_REQUEST['first_name'])) ? $_REQUEST['first_name'] : ''; + $_SESSION['last_name'] = (isset($_REQUEST['last_name'])) ? $_REQUEST['last_name'] : ''; + $_SESSION['organization'] = (isset($_REQUEST['organization'])) ? $_REQUEST['organization'] : ''; + $_SESSION['address'] = (isset($_REQUEST['address'])) ? $_REQUEST['address'] : ''; + $_SESSION['country'] = (isset($_REQUEST['country'])) ? $_REQUEST['country'] : ''; + $_SESSION['city'] = (isset($_REQUEST['city'])) ? $_REQUEST['city'] : ''; + $_SESSION['state'] = (isset($_REQUEST['state'])) ? $_REQUEST['state'] : ''; + $_SESSION['zip'] = (isset($_REQUEST['zip'])) ? $_REQUEST['zip'] : ''; + $_SESSION['phone'] = (isset($_REQUEST['phone'])) ? $_REQUEST['phone'] : ''; + $_SESSION['email'] = (isset($_REQUEST['email'])) ? $_REQUEST['email'] : ''; + $_SESSION['amount'] = (isset($_REQUEST['amount'])) ? $_REQUEST['amount'] : ''; + $_SESSION['invoice_num'] = (isset($_REQUEST['invoice_num'])) ? $_REQUEST['invoice_num'] : ''; + $_SESSION['card_type'] = (isset($_REQUEST['card_type'])) ? $_REQUEST['card_type'] : ''; + $_SESSION['x_card_num'] = (isset($_REQUEST['x_card_num'])) ? $_REQUEST['x_card_num'] : ''; + $_SESSION['exp_month'] = (isset($_REQUEST['exp_month'])) ? $_REQUEST['exp_month'] : ''; + $_SESSION['exp_year'] = (isset($_REQUEST['exp_year'])) ? $_REQUEST['exp_year'] : ''; + $_SESSION['x_card_code'] = (isset($_REQUEST['x_card_code'])) ? $_REQUEST['x_card_code'] : ''; + $_SESSION['comment'] = (isset($_REQUEST['comment'])) ? $_REQUEST['comment'] : ''; + $_SESSION['payment_method'] = (isset($_REQUEST['payment_method'])) ? $_REQUEST['payment_method'] : ''; +} ?>