0

我有一个付款页面,付款值将自动填写。所以我不想让用户提交该页面。我怎样才能自动提交我的页面?

我的代码是

   include "configaration/config.php";
  // Merchant key here as provided by Payu
  $MERCHANT_KEY = "4LbrUG";

 // Merchant Salt as provided by Payu
  $SALT = "EhDp06FA";

// End point - change to https://secure.payu.in for LIVE mode
  $PAYU_BASE_URL = "https://test.payu.in";

  $sucess_url = 'http://localhost/georamble/success.php';
  $failur_url = 'http://localhost/georamble/failure.php';
  $action = '';
  $posted = array();
   if(!empty($_POST)) {
    foreach($_POST as $key => $value) {    
      $posted[$key] = $value; 
       }
   }
  $formError = 0;

    if(empty($posted['txnid'])) {
    // Generate random transaction id
  $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
  } else {
   $txnid = $posted['txnid'];
 }
  $hash = '';
  // Hash Sequence
  $hashSequence =   "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
  if(empty($posted['hash']) && sizeof($posted) > 0) {
     if(
      empty($posted['key'])
      || empty($posted['txnid'])
      || empty($posted['amount'])
      || empty($posted['firstname'])
      || empty($posted['email'])
      || empty($posted['phone'])
      || empty($posted['productinfo'])
      || empty($posted['surl'])
      || empty($posted['furl'])
      || empty($posted['service_provider'])
   ) {
     $formError = 1;
   } else {
    //$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
    $hashVarsSeq = explode('|', $hashSequence);
      $hash_string = '';    
     foreach($hashVarsSeq as $hash_var) {
     $hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
        $hash_string .= '|';
     }
       $hash_string .= $SALT;
       $hash = strtolower(hash('sha512', $hash_string));
       $action = $PAYU_BASE_URL . '/_payment';
   }
   } elseif(!empty($posted['hash'])) {
     $hash = $posted['hash'];
     $action = $PAYU_BASE_URL . '/_payment';
  }
//data from previous page
     if(isset($_POST['submit1']))

    {
    $packname = $_POST['pname'];
    $package_price = $_POST['advn_pay'];

    $person = $_POST['person'];
    $date = $_POST['date'];
    $date = date('Y-m-d', strtotime($date));
    $package_id = $_POST['pkid'];

    $wallet_amount = $_POST['wallet_amount'];
    $wallet_amount_use = 0;

    if(isset($_POST['wuamount']))
    {
       $wallet_amount_use = $_POST['wuamount'];
    }

     $ref_no =rand(20,10000000);
     $pay_status = "unpaid";
    $req_status = "requested";
    $wallet_update_money=  $wallet_amount - $wallet_amount_use;

     $update= mysql_query("UPDATE wallet SET amount='$wallet_update_money' WHERE user_id='$login_session'");

    //fetch a user name 
    $query = mysql_query("select * from user where user_id= '$login_session'"); 

   if(!$query)
    {
      echo "error";
    }

 while($row=mysql_fetch_array($query))
   {
     $name =  $row['first_name'];
     $email =  $row['email'];
     $contact_number =  $row['contact_number'];
   }

    $p_name=$_POST['name'];
    $age=$_POST['age'];


      for($i=0;$i<count($p_name);$i++)
       {
       $qry_add="INSERT INTO trvel_person_details (ref_user_id,ref_cus_name,cus_name,cus_age,travel_date)
     VALUES ('$login_session', '$name','$p_name[$i] ','$age[$i]','$date')";
    if(!mysql_query($qry_add))
    {
    die('Error: ' . mysql_error());
    }
   }

      $total_amount= $package_price - $wallet_amount_use ; //total amount



      $qry="INSERT INTO pack_req (user_id,user_name,package_id,pacakage_name,amount,date_jrny,no_person,refrence_number,payment_status,req_status)

     VALUES ('$login_session', '$name','$package_id ','$packname','$total_amount','$date ','$person','$ref_no','$pay_status ','$req_status')";
    if(!mysql_query($qry))
    {
    die('Error: ' . mysql_error());
    }
    }



   ?>

   <html>
    <head>
    <script>
     var hash = '<?php echo $hash ?>';
       function submitPayuForm() {
          if(hash == '') {
          return;
           }

            var payuForm = document.forms.payuForm;
 payuForm.submit();
         }
       </script>

         </head>
        <body onload="submitPayuForm()">
        <h2>PayU Form</h2>
        <br/>
          <?php if($formError) { ?>

       <span style="color:red">Please fill all mandatory fields.</span>
         <br/>
         <br/>
       <?php } ?>
        <form action="<?php echo $action; ?>" method="post" id="payuForm" name="payuForm">
  <input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
  <input type="hidden" name="hash" value="<?php echo $hash ?>"/>
  <input type="hidden" name="txnid" value="<?php echo $txnid ?>" />
  <table>
    <tr>
      <td><b>Mandatory Parameters</b></td>
    </tr>
    <tr>
      <td>Amount: </td>
      <td><input name="amount" id="amount" value="<?php echo (empty($posted['amount'])) ? $total_amount : $posted['amount'];  ?>" /></td>
      <td>First Name: </td>
      <td><input name="firstname" id="firstname" value="<?php echo (empty($posted['firstname'])) ? $name : $posted['firstname']; ?>" /></td>
    </tr>
    <tr>
      <td>Email: </td>
      <td><input name="email" id="email" value="<?php echo (empty($posted['email'])) ? $email : $posted['email']; ?>" /></td>
      <td>Phone: </td>
      <td><input name="phone" value="<?php echo (empty($posted['phone'])) ? $contact_number : $posted['phone']; ?>" /></td>
      <td>transation Id: </td>
      <td><input name="txnid" value="<?php echo (empty($posted['txnid'])) ? $ref_no : $posted['txnid']; ?>" /></td>
    </tr>


    <tr>
      <td>Product Info: </td>
      <td colspan="3"><textarea name="productinfo"><?php echo (empty($posted['productinfo'])) ? $packname : $posted['productinfo'] ?></textarea></td>
    </tr>
    <tr>
      <td>Success URI: </td>
      <td colspan="3"><input name="surl" value="<?php echo (empty($posted['surl'])) ? $sucess_url : $posted['surl'] ?>" size="64" /></td>
    </tr>
    <tr>
      <td>Failure URI: </td>
      <td colspan="3"><input name="furl" value="<?php echo (empty($posted['furl'])) ? $failur_url : $posted['furl'] ?>" size="64" /></td>
    </tr>

    <tr>
      <td colspan="3"><input type="hidden" name="service_provider" value="payu_paisa" size="64" /></td>
    </tr>


      <?php if(!$hash) { ?>
      <td colspan="4"><input type="submit" value="Submit" /></td>
      <?php } ?>
    </tr>
  </table>
</form>

即使我尝试过使用一个 javascript 来自动提交表单

  <script type="text/javascript">
   $(document).ready(function(){
  $("#payuForm").submit();
     });
 </script>

但它仍然没有重定向。怎么能这样。任何提示或帮助。对不起,我的英语不好

4

3 回答 3

2

创建一个隐藏的提交类型按钮(即 display:none;),通过 jquery 加载页面后自动点击它(即 $('#submit').click() ),创建一个点击提交按钮的函数,之后调用它页面加载...

编辑:HTML:

<form ...>
...
<input type="submit" id="submit" style="display:none;" />
</form>

Javascript:

function submit_click(){
 $("#submit").click();
}

现在,当您调用自动表单填充数据的函数时,请在最后一行调用此函数submit_click();

于 2015-11-17T06:50:36.107 回答
1

请记住,如果您没有启用的提交按钮(无论是输入还是按钮,type="submit"),某些浏览器不会让您触发“提交”事件

因此,您需要在表单中添加一个按钮,如果您不希望它显示,您可以添加

#button {
   display: none;
   visibility: hidden;
}
于 2015-11-17T09:55:36.070 回答
1

尝试这个

<script>
$(document).ready(function(){

$('#payuForm').trigger('submit');
})
</script>
于 2015-11-17T09:06:47.930 回答