我对 PHP 和编程比较陌生,所以请原谅我的无知和语言。
我有一个具有相同输入字段的多个实例的表单(见下文)。我有一个脚本可以处理输入数据,但前提是一次提交一组(也在下面)。我希望在表单的按钮上设置一个提交按钮,该按钮将为页面上的多个数据集执行脚本。
有谁知道我怎样才能让它工作?我无法重命名变量(我试过了),因为接收服务器需要数据标签完全如下所示。任何帮助/方向将不胜感激。谢谢!
我的表格:
<form method="post" action="<?php echo (AUTHORIZENET_SANDBOX ? AuthorizeNetDPM::SANDBOX_URL : AuthorizeNetDPM::LIVE_URL)?>" id="checkout_form">
<?php
$time = time();
$fp_sequence = $time;
$fp = AuthorizeNetDPM::getFingerprint(AUTHORIZENET_API_LOGIN_ID, AUTHORIZENET_TRANSACTION_KEY, $amount, $fp_sequence, $time);
$sim = new AuthorizeNetSIM_Form(
array(
'x_amount' => $amount,
'x_fp_sequence' => $fp_sequence,
'x_fp_hash' => $fp,
'x_fp_timestamp' => $time,
'x_relay_response'=> "TRUE",
'x_relay_url' => $coffee_store_relay_url,
'x_login' => AUTHORIZENET_API_LOGIN_ID,
'x_test_request' => TEST_REQUEST,
)
);
echo $sim->getHiddenFieldString();
}
?>
<fieldset>
<H3>Card #1</H3>
<div>
<label>Amount</label>
<input type="text" class="text required" size="4" name="amount" value=""></input>
</div>
<div>
<label>Credit Card Number</label>
<input type="text" class="text required creditcard" size="15" name="x_card_num" value="6011000000000012"></input>
</div>
<div>
<label>Exp.</label>
<input type="text" class="text required" size="4" name="x_exp_date" value="04/15"></input>
</div>
<div>
<label>CCV</label>
<input type="text" class="text required" size="4" name="x_card_code" value="782"></input>
</div>
</fieldset>
<fieldset>
<div>
<label>First Name</label>
<input type="text" class="text required" size="15" name="x_first_name" value="John"></input>
</div>
<div>
<label>Last Name</label>
<input type="text" class="text required" size="14" name="x_last_name" value="Doe"></input>
</div>
</fieldset>
<fieldset>
<div>
<label>Address</label>
<input type="text" class="text required" size="26" name="x_address" value="123 Four Street"></input>
</div>
<div>
<label>City</label>
<input type="text" class="text required" size="15" name="x_city" value="San Francisco"></input>
</div>
</fieldset>
<fieldset>
<div>
<label>State</label>
<input type="text" class="text required" size="4" name="x_state" value="CA"></input>
</div>
<div>
<label>Zip Code</label>
<input type="text" class="text required" size="9" name="x_zip" value="94133"></input>
</div>
<div>
<label>Country</label>
<input type="text" class="text required" size="22" name="x_country" value="US"></input>
</div>
</fieldset>
<fieldset>
<H3>Card #2</H3>
<div>
<label>Amount</label>
<input type="text" class="text required" size="4" name="amount" value=""></input>
</div>
<div>
<label>Credit Card Number</label>
<input type="text" class="text required creditcard" size="15" name="x_card_num" value="6011000000000012"></input>
</div>
<div>
<label>Exp.</label>
<input type="text" class="text required" size="4" name="x_exp_date" value="04/15"></input>
</div>
<div>
<label>CCV</label>
<input type="text" class="text required" size="4" name="x_card_code" value="782"></input>
</div>
</fieldset>
<fieldset>
<div>
<label>First Name</label>
<input type="text" class="text required" size="15" name="x_first_name" value="John"></input>
</div>
<div>
<label>Last Name</label>
<input type="text" class="text required" size="14" name="x_last_name" value="Doe"></input>
</div>
</fieldset>
<fieldset>
<div>
<label>Address</label>
<input type="text" class="text required" size="26" name="x_address" value="123 Four Street"></input>
</div>
<div>
<label>City</label>
<input type="text" class="text required" size="15" name="x_city" value="San Francisco"></input>
</div>
</fieldset>
<fieldset>
<div>
<label>State</label>
<input type="text" class="text required" size="4" name="x_state" value="CA"></input>
</div>
<div>
<label>Zip Code</label>
<input type="text" class="text required" size="9" name="x_zip" value="94133"></input>
</div>
<div>
<label>Country</label>
<input type="text" class="text required" size="22" name="x_country" value="US"></input>
</div>
</fieldset>
<input type="submit" value="BUY" class="submit buy">
</form>
我的脚本:
<?php
require_once 'coffee_store_settings.php';
if ($METHOD_TO_USE == "AIM") {
$transaction = new AuthorizeNetAIM;
$transaction->setSandbox(AUTHORIZENET_SANDBOX);
$transaction->setFields(
array(
'amount' => $amount,
'card_num' => $_POST['x_card_num'],
'exp_date' => $_POST['x_exp_date'],
'first_name' => $_POST['x_first_name'],
'last_name' => $_POST['x_last_name'],
'address' => $_POST['x_address'],
'city' => $_POST['x_city'],
'state' => $_POST['x_state'],
'country' => $_POST['x_country'],
'zip' => $_POST['x_zip'],
'email' => $_POST['x_email'],
'card_code' => $_POST['x_card_code'],
)
);
$response = $transaction->authorizeAndCapture();
if ($response->approved) {
// Transaction approved! Do your logic here.
header('Location: thank_you_page.php?transaction_id=' . $response->transaction_id);
} else {
header('Location: error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text);
}
} elseif (count($_POST)) {
$response = new AuthorizeNetSIM;
if ($response->isAuthorizeNet()) {
if ($response->approved) {
// 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;
} else {
// There was a problem. Do your logic here.
// Redirect the user back to your site.
$return_url = $site_root . 'error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text;
}
echo AuthorizeNetDPM::getRelayResponseSnippet($return_url);
} else {
echo "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config.php";
}
}