0

I have a paypal button and I need to get some information when it is clicked: Name and name of post.

I have this input field for the name.

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

Then the paypal button.

<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>

This works, item_name get title of post and I see it in details of paypal transiction.

How pass the name in value of item_name with the_title(); ???

4

2 回答 2

0

好的,我解决了。在您的脚本中,我添加了以下内容:

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; 
} 
于 2019-04-17T17:31:17.230 回答
0

您可以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;
于 2019-04-17T16:46:35.927 回答