简体   繁体   中英

get option value into php variable before submit form so that it can be process to generate signature

Problem

I have a form to select "amount" value that has dropdown selection and i need to get that dropdown option value before i submit the form so that i can use that option value "amount" which will be save into php variable ($amount) to do some massaging to generate hash signature.

Only this then signature value will be submitted the form along with actual amount option value. How to get this $amount php variable before submission?

My level is on basic html and php but not in javascript, jquery or AJAX.

Code

<form role="form" method="post" name="ePayment" action="https://payment.ipay88.com.my/ePayment/entry.asp">

<div class="form-group">
<label>Donation Amount</label>

<select class="chosen-select input-xs form-control" name="Amount">
 <option value="" disabled selected>Please Select</option>
 <option value="10.00">USD 10</option>
 <option value="20.00">USD 20</option>
 <option value="50.00">USD 50</option>
 <option value="">Other Amount</option> 
</select>
</div>

<?php
//i want option value to save in this $amount before press submit button not by using $_POST
$amount = $_POST["Amount"];  

//from this $amount variable i want to massage it like below output ($newamounts) before put to generate hash signature
if ($amount == "10.00") {$newamount = "1000";}
elseif ($amount == "20.00") {$newamounts = "2000";}
elseif ($amount == "50.00") {$newamounts = "5000";}

//generate hash signature
function iPay88_signature($source) {return hash('sha256', $source);}

//format require before generate hash signature
$source = 'appleCodeMBA123'.$newamounts.'USD';

//save hash signature into $signature variable  
$signature = iPay88_signature($source);
?>

<INPUT type="hidden" name="Signature" value="<?php echo $signature; ?>">
<INPUT type="hidden" name="ResponseURL" value="https://RESPONSEURL.php">
<INPUT type="hidden" name="BackendURL" value="https://BACKENDURL.php">

<button type="submit" name="Submit" value="Proceed">Donate</button>

</form>

You have to call javascript function

 onclick=submit()

then use

 if($_POST['Amount']==""){} 

put all code inside it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM