Hi all - I suspect this question is going to be a bit basic, but it’s because I’m not knowledgable when it comes to PHP. Can you use a custom field from an entry within PHP that’s in a template? I have some PHP running inside a template now and everything is fine except if I try to use a custom field within the PHP itself. I’ll explain by showing the code here:
<?php
} else {
//structure information for JSON Serialization
$recipient['@recipientType'] = 'CUSTOMER';
$recipient['firstName'] = $_POST["Fname"];
$recipient['lastName'] = $_POST["Lname"];
$recipient['gender'] = $_POST["gender"];
$recipient['address1'] = $_POST["address1"];
$recipient['address2'] = $_POST["address2"];
$recipient['city'] = $_POST["city"];
$recipient['province'] = $_POST["province"];
$recipient['postalCode'] = $_POST["postalCode"];
$recipient['language'] = 'E';
$fulfillment['@programId'] = 51;
$fulfillment['@fulfillmentType'] = "DOWNLOADABLE";
$fulfillment['amount'] = "1";
$fulfillment['recipient'] = $recipient;
//convert to JSON
$json = json_encode($fulfillment);
require_once "http://www.stitesting.com/test/RestClient.php";
//create Client object for sending the query
$rest = new RestClient("vezco","apple23");
$rest->setDestination("https://dev001-srv.samplingtechnologies.com/api/fulfillment/");
$rest->setContentType('JSON');
$rest->setAcceptHeader('JSON');
//actual sending of query
$rest->post($json);
//we want to be sure that we get a success. You could probably do more error checking, for example if a 400 code was returned (missing data)
if($rest->getResponseCode() != 200) {
?>
We are sorry, but we are currently encountering technical difficulties. Please try again later.
<?php
//DEBUG Only. If we have an error, spit out the error details so we can debug
echo $rest->getResponseBody();
} else {
//Decode the result so we can get the downloadUrl property
$result = $rest->getResponseBody();
$jsonResult = json_decode($result);
?>
{product_registration_thanks}
<h1>{thanks_title}</h1>
{thanks_body}
Click on <a >{'downloadUrl'}; ?>'>this link</a> for your electronic sample.
{/product_registration_thanks}
<?php
}
}
?>
I have this entire segment of the page surrounded by an entries tag with a single entry ID parameter. It includes a custom field for “programId”, which is a declared variable in the PHP in the JSON serialization for this form submission. Right now, it’s hardcoded to “51” but I’d like for it to read the value that’s entered in the entry. But when i try to substitute the custom field name in place of the hard-coded “51” my page goes blank. I’m suspecting that there must be some tags or characters that must surround the custom field name in order to use it this way, is that it? To protect it from being misidentified as a php function?
Thanks!