Вот страница пожертвования.
Я пытался сохранить данные в MYSQL db и свернуть необходимую информацию в шлюз EPayment (Paydollar), например, merchantId, amount, currCode ....
Если я активирую <form name="payFormCcard" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
, он перейдет в хранилище БД и не будет выполнять действие по оплате.
Если я активирую <form action="https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp" id="payFormCcard" method="post" name="payFormCcard">
, он не будет выполнять хранилище MYSQL.
Теперь я закрываю оба метода действия формы: <form name="payFormCcard" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
& <form action="https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp" id="payFormCcard" method="post" name="payFormCcard">
, действия отправки не выполняются.
Похоже, он не может передать параметры в шлюз EPaymentby POST-CURL
curl_setopt($ch, CURLOPT_URL,"https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp");
curl_setopt($ch, CURLOPT_POST, 1);
=> Похоже, этот код не может быть активирован.
Как мне исправить код?
create.php
<?php
// Include config file
require_once 'database.php';
header("Content-Type:text/html; charset=big5");
print_r($_POST);
// Define variables and initialize with empty values
$CName = $Address = $Phone = $Amount= $Purpose= $Ticket = "";
$CName_err = $Address_err = $Phone_err = $Amount_err = $Purpose_err = $Ticket_err="";
// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate name
$input_CName = trim($_POST["CName"]);
if (empty($input_CName)) {
$CName_err = "Please enter a name.";
} elseif (!filter_var(trim($_POST["CName"]), FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-zA-Z'-.\s ]+$/")))) {
$CName_err = 'Please enter a valid name.';
} else {
$CName = $input_CName;
}
// Validate address
$input_Address = trim($_POST["Address"]);
if (empty($input_Address)) {
$Address_err = 'Please enter an address.';
} else {
$Address = $input_Address;
}
// Validate Phone
$input_Phone = trim($_POST["Phone"]);
if (empty($input_Phone)) {
$Phone_err = "Please enter your phone number again.";
} elseif (!ctype_digit($input_Phone)) {
$Phone_err = 'Please enter a positive integer value.';
} else {
$Phone = $input_Phone;
}
// Validate Amount
$input_Amount = trim($_POST["Amount"]);
if (empty($input_Amount)) {
$Amount_err = "Please enter the amount.";
} elseif (!ctype_digit($input_Amount)) {
$Amount_err = 'Please enter a positive integer value.';
} else {
$Amount = $input_Amount;
}
// Check input errors before inserting in database
if (empty($CName_err) && empty($Address_err) && empty($Amount_err) && empty($Phone_err)) {
// Prepare an insert statement
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO donation (CName, Address, Phone, Amount ,Ticket, Purpose) VALUES (?, ?, ?, ? ,?, ?)";
$q = $pdo->prepare($sql);
$q->execute(array($CName, $Address, $Phone, $Amount ,$Ticket ,$Purpose));
Database::disconnect();
header("Location: index.php");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array (
'merchantId' => 'sth',
'orderRef' => 'sth',
'currCode' => 'sth',
'mpsMode' => 'NIL',
'successUrl' =>'http://www.yourdomain.com/Success.html',
'failUrl' =>'http://www.yourdomain.com/Fail.html',
'cancelUrl'=>'http://www.yourdomain.com/Cancel.html',
'payType' =>'sth',
'lang' =>'sth',
'payMethod' => 'sth',
'secureHash'=> 'sth'
)));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
}
?>
<!DOCTYPE html>
<!--<html lang="en">-->
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>
</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
.wrapper{
width: 500px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h2>
form
</h2>
</div>
<p>
</p><br>
<p>
</p><!-- <form name="payFormCcard" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> -->
<!-- <form action="https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp" id="payFormCcard" method="post" name="payFormCcard"> -->
<div class="form-group <?php echo (!empty($CName_err)) ? 'has-error' : ''; ?>">
<label>*English Name</label> <input class="form-control" name="CName" type="text" value="<?php echo $CName; ?>"> <span class="help-block"><?php echo $CName_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($Phone_err)) ? 'has-error' : ''; ?>">
<label>*Contact No.</label> <input class="form-control" name="Phone" type="text" value="<?php echo $Amount; ?>"> <span class="help-block"><?php echo $Phone_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($Address_err)) ? 'has-error' : ''; ?>">
<label>* Email Address</label>
<textarea class="form-control" name="Address"><?php echo $Address; ?></textarea> <span class="help-block"><?php echo $Address_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($Amount_err)) ? 'has-error' : ''; ?>">
<label>*Donation Amount</label> <input class="form-control" list="Amount" multiple name="Amount"> <datalist id="Amount">
<option value="100">
</option>
<option value="300">
</option>
<option value="500">
</option>
<option value="1000">
</option>
</datalist> <span class="help-block"><?php echo $Amount_err; ?></span>
</div>
</div><input class="btn btn-primary" type="submit" value="Submit"> <a class="btn btn-primary" href="index.php">Cancel</a>
</form>
<p>
</p><br>
<p>
Thank you for your support
</p>
</div>
</div>
</div>
</div>
</body>
</html>