【问题标题】:How to pass value of a input to other input in paypal button如何将输入值传递给贝宝按钮中的其他输入
【发布时间】:2019-09-07 22:52:00
【问题描述】:

我有一个 paypal 按钮,点击它时我需要获取一些信息: 职位名称和名称。

我有这个名称的输入字段。

<span class="intestazione-form">Name*</span><br>
<input type="text" id="searchTxt" name="name" value="" size="40" class=" nome-input"  placeholder="Insert your name">

然后是贝宝按钮。

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">


<input type="hidden" name="item_name" value="<?php echo the_title(); ?> ">

<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="xxxxxx" />
<input  id="btnSubmit" class="btn" type="submit" value="DONA CON PAYPAL"  type="image" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button"  disabled/>
img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1" />
</form>

这行得通,item_name 得到帖子的标题,我在 paypal transiction 的详细信息中看到它。

如何通过 the_title() 传递 item_name 的值中的名称; ???

【问题讨论】:

    标签: php wordpress input paypal-buttons


    【解决方案1】:

    好的,我解决了。在你的脚本中,我添加了这个:

    function submitForm(){ 
    var nome_post = 'CAMPAGNA: <?php echo the_title(); ?> NOME DONATORE: ' ; 
    var name = document.getElementById('searchTxt').value; 
    var res = nome_post.concat(name); 
    document.getElementById('item_name').value = res; 
    if(name) return true; 
    else return false; 
    return true; 
    } 
    

    【讨论】:

      【解决方案2】:

      您可以在表单标签中使用onsubmit,如下所示

      <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" onsubmit="return submitForm();" >
      

      使用函数submitForm可以填充元素item_name

      <script type="text/javascript">
      function submitForm(){
          var name = document.getElementById('searchTxt').value;
          document.getElementById('item_name').value = name;
          if(name) 
             return true;
          else
             return false;
      
          return true;
      }
      </script>
      

      理解的完整代码

      <span class="intestazione-form">Name*</span><br>
      <input type="text" id="searchTxt" name="name" value="" size="40" class=" nome-input"  placeholder="Insert your name">
      
      <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" onsubmit="return submitForm();" >
      
      
      <input type="hidden" name="item_name" id="item_name" value="<?php //echo the_title(); ?> ">
      
      <input type="hidden" name="cmd" value="_s-xclick" />
      <input type="hidden" name="hosted_button_id" value="xxxxxx" />
      <input  id="btnSubmit" class="btn" type="submit" value="DONA CON PAYPAL" />
      <img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1" />
      </form>
      <script type="text/javascript">
      function submitForm(){
          var name = document.getElementById('searchTxt').value;
          document.getElementById('item_name').value = name;
          if(name) 
             return true;
          else
             return false;
      
          return true;
      }
      </script>
      

      您可以再创建一个隐藏字段,例如

      <inout type="hidden" name="field_name" id="field_name" />
      

      之后的javascript

      document.getElementById('field_name').value = name;
      

      【讨论】:

      • 它有效。但是对我来说有一个错误。我需要两个信息:姓名和帖子标题。我得到带有 php 代码和函数 the_title() 的帖子标题。如何获取这两个信息?
      猜你喜欢
      • 2012-09-25
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 2015-02-21
      • 2017-08-16
      • 1970-01-01
      相关资源
      最近更新 更多