How to print an HTML code from a variable in PHP? - php

I am developing a PHP site, and have encountered the following problem.
I have this line of code:
<div id="buynow"><?php echo $buynow; ?></div>
The variable $buynow has an html code (a paypal buy now button), and I would like to print/echo the html code that it gets processed.
With the current code, it prints the html code itself, not the desired result.
Thanks in advance
String:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXXXXXXXXXX">
<table>
<tr><td><input type="hidden" name="on0" value="Colors">Colors</td></tr><tr><td><select name="os0">
<option value="Black">Black </option>
<option value="White">White </option>
</select> </td></tr>
</table>
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Note: The value is replaced to XXXXXXXXX on purpose, in the code it is the original.

maybe try this:
<div id="buynow"><?php echo htmlspecialchars_decode($buynow); ?></div>
or use
<div id="buynow"><?php echo html_entity_decode($buynow); ?></div>

The method I use on simple Paypal button sites is to save the button code as little php files on their own (can just be the html making up the Paypal button). Then "include" the external file at the relevant point. It makes managing the buttons relatively easy without changing your source code.
Other than that, it seems that your page may not actually be a php page.

Related

How to add specific amount in PayPal Donation

I'm trying to add a donation page with paypal integration. It works perfectly fine. But what I want to add is to first sign the form from my site and then send it to paypal as well as the selected amount of donation. I've also trid to put this code <input type="hidden" name="amount" value="<?php echo $total; ?>"> as per my research. But it's still not working. Please see my code below for your review/reference.
Code
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="QWEVB36VTJYEG">
<input type="hidden" name="amount" value="88.00">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
The result would be just like this: (Blank Value) (The value must be 88.00)
As far as I know, donations on Paypal can't be restricted to one single value. The amount input is ignored, to be sure that people who will donate are not being manipulated and forced to pay a price they did not choose.
However, if you want to propose some fixed prices, here is a Paypal Community code which will help you doing that.
EDIT: Here is a StackOverflow answer which is pretty clear and confirms my thoughts.

How to make button paypal with our variable total in php

Hy guys, How to make button paypal with our variable $total, I make button paypal automatic in paypal.com, but I don't know how to change code with my variable total in my program, and change this value with my email <input type="hidden" name="hosted_button_id" value="6GRSJ868MQYPS">
this is my code can any solution with my problem ?
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6GRSJ868MQYPS">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Hosted buttons hide those parameters, so you won't be able to dynamically adjust the $total when the page loads. If you want to do that you'll need to create a button that is not hosted, and then you would have an "amount" parameter you could pass your $total into.

PayPal and Forms not working

I've recently redesigned a site I'd originally built 2/3 years back. We used PayPal buttons for Gift Vouchers and Deposits, but neither are working on the new version.
One of the pages affected is http://www.louiseballantine.com/giftvouchers.php - you'll see that the buttons display properly, but nothing happens when clicked.
However, the old version of the page (and I've added the same code for the new button) works perfectly: http://www.louiseballantine.com/giftvouchers_old.php
Here is the code for the first button (copied and pasted from PayPal):
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="497ZF2RU65YJQ">
<input type="image" src="http://www.louiseballantine.com/img/voucher05.png" border="0" width="100%" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
As I said previously, there's also an issue with the contact forms, so this may not be a specific problem with the PayPal code. However, any assistance would be gratefully received.
Thank you.
Problem solved by removing bootstrap's integrated form-handling scripts.

How do I edit the input fields of paypal sandbox?

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="QHHYRZWR44QMY">
<table>
<tr><td><input type="hidden" name="on0" value="WeBoss - Downpayment">WeBoss - Downpayment</td></tr>
<tr><td><select name="os0">
<option value="Combat">Combat P1,000.00 PHP</option>
<option value="Battlefield">Battlefield P1,500.00 PHP</option>
<option value="Warfield">Warfield P2,100.00 PHP</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="PHP">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
Cancel
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
i would like to edit the price, how would i do that? and also i tried in "BUY NOW" button and change amount but still it wont change the price.
is there a way to edit the paypal sandbox page?
With a hosted buttons, you cannot dynamically change the amount in the code.
To be able to change the amount in the code, use a non-hosted button instead. To create a non-hosted button, log in to your paypal.com account to re-create the button again, but this time, click on Step 2 and un-check the option to save button at PayPal. After clicking on 'create button' click on 'remove code protection' to get a clear-text button code.
NB. However, using a clear-text button code is un-secure as someone can change the values in the code prior to submission of the button.
So instead, you can use 'BMCreateButton API' to dynamically create hosted or encrypted buttons.
https://developer.paypal.com/webapps/developer/docs/classic/api/button-manager/BMCreateButton_API_Operation_NVP/
Samples http://paypal.github.io/sample-apps/ [Classic API Samples]

How to display PHP code as a string inside other PHP code

I need to paste this code at admin panel and then display Paypal Button on website.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6UKjJ8hU6ML5f">
<input type="hidden" name="custom" value="<?php print($_SESSION['mid'].'-'.$_SESSION['mps']);?>">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Then, need to display this code on website using following code.
print $rs->fields("ppbutton");
Now, problem is that due to PHP code inside Paypal form, whenever I try to print above value (paypal button) on website, it's giving error because of PHP code inside another PHP code.
I also think, print htmlentities($rs->fields("ppbutton"));
is the best option for you.
You can get the most recent updates about the function from this site.
http://php.net/manual/en/function.htmlentities.php
print htmlentities($rs->fields("ppbutton"));

Categories