We are going to create a service form , in which customer can enter details, select service and pay cash .
-> Only one form is shown to user ->user select service with price and fill the other detail->Submitting the details , so data's are saved in backend->After saving data, form2 need to work automatically ,but the second form input value is depend on the first form input values and cash .
Which is the best way to implement this ?, two form in same page or different page ?
Can i use ajax for this so that customer need to stay in same page ?
we nee to hide our merchant id , merchant secret from inspect element
Please give example . please see my two forms Form-1
<form method="post" action="" name="form1" id="form1">
Your name<input type="text" name="cl_name">
Service < input type="checkbox" name="check-1" value="10"> Wash
< input type="checkbox" name="check-2" value="10"> clean
<input type="submit" name="submit" value="submit">
</form>
Form-2
<form method="post" action="paymet_gateway_url" id="form2">
Name <input type="text" value="Form1 your name value" name="p_name" id="p_name">
Value<input type="text" value="Form1 service value (either 10 or 20 )" name="p_cash" id="p_cash">
<inpu type="hidden" value="return url" name="p_r_url">
<input type="submit" name="submit" value="submit">
</form>
You can do this in different ways...
for Example:
payment.php ---> wrper_payment.php ---> payment_gateway_url
for Example:
order.php ---> payment.php (which has the merchant id) ---> payment_gateway_url
Dear, Javascript and ajax are not different, but if you want to make it very much secured, I suggest you use AngularJS, it's not hard to learn and also faster to execute and implement.
For Example: payment.php
<?php
// For ajax use
$output = array('status'=>false,'error'=>''); //for JSON output
$switch($_POST['action']){
case 'payment1':
//process payment1
break;
case 'payment2':
//process payment2
break;
}
//please dont forgot to set the header
header('Content-Type:application/json;)';
echo json_encode($output);
For Example: order.php
assuming that you are using jQuery for ajax call
<Body>
....
<button onclick="payment('payment1');"> Payment Option 1 </button>
<button onclick="payment('payment2');"> Payment Option 2 </button>
<Script type="text/javascript">
function payment(option){
$.post('payment.php',{action: option},function(data){
//provide feedback to customer
});
}
</script>
</body>
One last thing, do use PHP wrapper because it will hide all your credentials for security...
Best Luck
Ans:
(1) Two form in one page
(2) Of course you can use Ajax
(3) This is an irrelevant question. Because JavaScript has a specific library which is know as JQuery, and Ajax is a JQuery method.
Here is how you can implement the feature.