Get back HTML code from json encoded string - php

We are trying to get some HTML source code using an API written in PHP. The PHP code uses json_encode to encode the response and then echoes it. The response we receive is similar to this.
{"status":true,"message":"Form fetched.","html":"
<!DOCTYPE html>\n\n
<html>\n\n
<head>\n\n<\/head>\n\n
<body onload=\"document.form.submit()\">\n\n\t
<div>\n\t\t\t
<img src='https:\/\/www.example.com\/resource\/images\/loader.gif' width='300px' height='300px'\/>\n\t\t\tPlease wait while we redirect you...\n\t<\/div>\n\n\t
<form name='form' method='POST' action='https:\/\/test.test.com\/_payment'>\n\t\t
<input type='hidden' name='key' value='randomFFx'>\n\t\t
<input type='hidden' name='txnid' value='YHOOCH31DG90HeQpc8h7'>\n\t\t
<input type='hidden' name='productinfo' value='Adding to user.'>\n\t\t
<input type='hidden' name='amount' value='100'>\n\t\t
<input type='hidden' name='firstname' value='test'>\n\t\t
<input type='hidden' name='lastname' value='test'>\n\t\t
<input type='hidden' name='email' value='support#example.com'>\n\t\t
<\/form>\n<\/body>\n<\/html>"}
How do I get a proper HTML code without \n\t which I can show in the webview. Currently due to these, the form isn't getting submitted automatically. We have tried replacing \n, \t, \ with , but is there a better method to retrieve the HTML code. Thanks in advance for all your help and suggestions.

Related

PHP POST tmpfile()

I am trying to create live editing of a server file on an other server. I managed to download and save it as tmpfile(). After editing the file I want to save the changes. my HTML code looks like this:
<body>
<form method='post'>
<textarea name='text' class='textfield' id='textf'>$text</textarea>
<input type='submit'>
<input type='hidden' name='valuea' value='$server'>
<input type='hidden' name='valueb' value='$user'>
<input type='hidden' name='valuec' value='$safelocation'>
<input type='file' name='temp' value='$tempfile'>
</form>
</body>
I am not able to send the $tempfile again to my php code. I tried to cast the POST value as resource but that will not be a/the same temp file. $file = (resource)($_POST['temp']);
How could I manage to send the same file I editied to the same php script and use it again?

2checkout.com payment method integration in PHP

Can any one help me with 2checkout.com payment method integration in PHP step wise? I have written a form as it is described in documentation of 2checkout.com site for inline process. After submitting the form it shows that the payment is successful but I didn't receive any IPN result in my function. So hence it is proved that payment is not done.
I will be grateful if anyone helps me with this. sample code is listed below. What I have to do next after that to get exact response from 2checkout so that I can understand the payment has been successful.
<form id="2checkout" action='https://sandbox.2checkout.com/checkout/purchase' method='post'>
<input type='hidden' name='sid' value='111111111' />
<input type='hidden' name='mode' value='2CO' />
<input type='hidden' name='li_0_type' value='product' />
<input type='hidden' name='li_0_name' value='test title' />
<input type='hidden' name='li_0_price' value='212.00' />
<input type='hidden' name='x_receipt_link_url' value='http://myserver.com/ipn_twocheckout' />
<input type='hidden' name='card_holder_name' value='Joe Flagster' />
<input type='hidden' name='street_address' value='123 Main Street' />
<input type='hidden' name='street_address2' value='Suite 200' />
<input type='hidden' name='city' value='Townsville' />
<input type='hidden' name='state' value='Ohio' />
<input type='hidden' name='zip' value='43206' />
<input type='hidden' name='country' value='USA' />
<input type='hidden' name='email' value='mysample#gmail.com' />
<input type='hidden' name='phone' value='614-921-2450' />
</form>
<script type="text/javascript">document.getElementById('2checkout').submit();</script>
<script src="https://www.2checkout.com/static/checkout/javascript/direct.min.js"></script>
The easiest way to verify that a payment was successful is to simply validate it on the return, here's an example of a return validation, assuming that you are returning to this page after the purchase is complete at 2Checkout:
<?php
$hashSecretWord = 'tango'; //2Checkout Secret Word
$hashSid = 111111111; //2Checkout account number
$hashTotal = '212.00'; //Sale total to validate against
$hashOrder = $_REQUEST['order_number']; //2Checkout Order Number
$StringToHash = strtoupper(md5($hashSecretWord . $hashSid . $hashOrder . $hashTotal));
if ($StringToHash != $_REQUEST['key']) {
$result = 'Fail - Hash Mismatch';
} else {
$result = 'Success - Hash Matched';
}
echo $result;
simple problem:
your submitting payment in sandbox mode.
(https://sandbox.2checkout.com/checkout/purchase)
in this case "x_receipt_link_url" parameter will not work.
(it will only work for live account).
to test the response in your project.
login to your sandbox account. then navigate to
(please find the below attachments for clear idea)
Account tab=>site management tab.
then select the radio button Header Redirect.
then
Enter the approved url and affiliate url as : http://myserver.com/ipn_twocheckout (your site url to receive success callback and handling).
then save changes.
i hope this answer will help you.

HTML form's "action" doesnt carry over my $_GET data

I have a HTML form that acts as a "confirm deletion?" page and my "Back" button is playing up.
$string = "foo.php?id=" . $_POST['fooid'] . "&id2=" . $_POST['barid'];
<!-- ^^ this ends up being "foo.php?id=1&id2=2" -->
<form action='<?php echo $string; ?>'>
<input type='submit' value='Back'>
</form>
the problem is, when the button is pressed it links to foo.php without any of the $_GET data in my string, even though the string contains "id=1&id2=2"
P.S I changed the code above so people could better understand it, here is the raw code:
<?php
$string = "xrays.php?id=" . $_POST['visitid'] . "&id2=" . $_POST['patientid'];
?>
<form action='delete.php' method='post'>
<input type='hidden' name='xrayid' value='<?php $_POST['xrayid']?>'>
<input type='submit' name='submit' value='Confirm Delete?'>
</form>
<form action='<?php echo $string; ?>'>
<input type='submit' value='Back'>
</form>
Maybe it's not the best answer but I would like do something like that:
$string = "foo.php?id=" . $_POST['fooid'] . "&id2=" . $_POST['barid'];
<!-- ^^ this ends up being "foo.php?id=1&id2=2" -->
<form action='foo.php'>
<input type="hidden" name="fooid" value ="<php echo $_POST['fooid']; ?>" />
<input type="hidden" name="barid" value ="<php echo $_POST['barid']; ?>" />
<input type='submit' value='Back'>
</form>
This should work properly.
EDIT: change $_GET na $_POST
You need to put the get variable in the form hidden inputs, like so:
<form action='foo.php'>
<input type="hidden" name="id" value="1" />
<input type="hidden" name="id2" value="2" />
<input type='submit' value='Back'>
</form>
Or you could use a link:
Back
Let's start with form submission in general. W3C: Form Submission
Next, let's review $_GET and $_POST. PHP Manual: $_GET | PHP Manual: $_POST
In summary, inside of your <form> tag, use either method="get" or method="post". Only one of the superglobal arrays will be populated by successful controls, based upon your method of sending the data. I believe the query string must result from a GET request url (which may be the default), not just a plain string slapped into the action="" attribute. I could be wrong about the query string, but you have another problem. You are using two forms on one page. Presently, I think only one form's controls can be submitted successful at a time.
<form action='delete.php' method='post'> <!-- FORM 1 -->
<input type='hidden' name='xrayid' value='<?php $_POST['xrayid']?>'>
<input type='submit' name='submit' value='Confirm Delete?'>
</form>
<form action='<?php echo $string; ?>'> <!-- FORM 2, add a method="" attribute -->
<input type='submit' value='Back'>
</form>
Upon adding a method="get" to form two, it should become clear that a composite $_POST + $_GET request is not possible in the two form approach, and that you need to start with making a single, monolithic form instead of two modular ones. Using the type="hidden" attribute of an <input /> tag, inside of one form, as in #machineaddict's answer, will help. However, what will really help is if you explicitly use all the correct attributes of each tag so that you can spot errors like this in the future.
In a situation like this, it is helpful to know that the $_SERVER['QUERY_STRING'] element would hold the complete query string if your web server received one.
PHP Manual: $_SERVER

Using php in Form Action

here is my html code:
form action="add_answer.php?id=<?php echo $id;?>" form method="post" class="login">
The issue is that it directs me to the link: xxxxxx/add_answer.php?id=%3C?echo%20$id?%3E
The problem with that link is that it inserts the php code instead of echoing the variables value. Why is this happening?
Note: It does not actually have xxxxx in the link, I replaced the beginning part of the link sine it disallowed me to insert localserver into the link.
Don't do:
<form action="add_answer.php?id=<?php echo $id;?>" form method="post" class="login">
Do do:
<form action="add_answer.php" method="post" class="login">
<input type='hidden' name='id' value='<?php echo $id;?>' />
You should not include parameters in the action itself, but in the form. If you are echoing the line (a possible reason your PHP tag was not being parsed), do it like:
echo "<form action='add_answer.php' method='post' class='login'>";
echo "<input type='hidden' name='id' value='{$id}' />";

php4 to php5 call of another file-php with input type is not working

After a change from PHP4 to PHP5 a problem occurred, I cant find it in the migration FAQ.
<form method='post' action='galerie.php'>
<input type='hidden' name='kategorieid' value='$id'>
<input type='hidden' name='echtkategorie' value='$kategorie'>
<input type='hidden' value='' name='geaendert'>
<input name='imageField' type='image' src='../images/bearbeiten.gif' width='39' height='40' border='0' alt='Galerie "$kategorie" bearbeiten'>
I am calling galerie.php with some variables $id and $kategorie, but they wont appear in the galerie.php:
$_GET['id']
Won’t work in galerie.php I do $befehl="SELECT kategorie, id FROM $tabelle WHERE id='$kategorieid'"; but kategorieid is not there.
You are using method="post" which means that you should be using $_POST['id'] rather than $_GET['id'].

Categories