dounuo8797 2015-11-17 06:36
浏览 30

如何让我的页面自动提交?

I have one payment page where payment values will fill automatically . so i don't want allow that page to user to submit . how can i do auto submit of my page ?

my code is

   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>

even i have tried with one javascript to auto submit the form

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

but still its not redirecting . how can do this . any hint or help . sorry for my bad english

  • 写回答

3条回答 默认 最新

  • duanguangsong2380 2015-11-17 06:50
    关注

    Create a hidden submit type button(i.e. display:none;), after page load through jquery click on it automatically(i.e. $('#submit').click() ), Create a function for clicking on submit button, call it after page loads...

    EDIT: HTML:

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

    Javascript:

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

    Now, when your auto form populating data's function called, call this function in last line submit_click();

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?