Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2018-09-28 09:53:44
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,315
undefined php tags
i needed to add those two php scripts (below) at the beginning of a template. after this, i get lots of tag errors:
Notice: Undefined index: workout while parsing form None on page default
Notice: Undefined index: workoutd while parsing form None on page default
Notice: Undefined index: cartid while parsing form None on page default
Notice: Undefined index: webshop while parsing form None on page default
Notice: Undefined variable: wo_id while parsing form hopitude on page default
how to define those tags to txp?
the scripts:
<txp:php>
$wo_id = $_GET['workout'];
$wo_date = $_GET['workoutd'];
$cart_id = $_GET['cartid'];
$webshop = $_GET['webshop'];
$hopitude_url = "https://www.hopitude.com/";
</txp:php>
and
<txp:php>
//if workout id and workout date are in URL, add extra metadata to head
if ($wo_id !='' && $wo_date != '' ) {
//get the title via curl
$title = curl_init($hopitude_url."workouts/title/".$wo_id."/".$wo_date."/");
curl_setopt($title, CURLOPT_RETURNTRANSFER, true);
curl_setopt($title, CURLOPT_HEADER, 0);
echo '<meta property = "og:title" content = "'.curl_exec($title).'" />';
curl_close($title);
//get workout description via curl
$desc = curl_init($hopitude_url."workouts/description/".$wo_id."/");
curl_setopt($desc, CURLOPT_RETURNTRANSFER, true);
curl_setopt($desc, CURLOPT_HEADER, 0);
echo '<meta property = "og:description" content = "'.curl_exec($desc).'" />';
curl_close($desc);
//get workout image via curl
$image = curl_init($hopitude_url."workouts/image/".$wo_id."/");
curl_setopt($image, CURLOPT_RETURNTRANSFER, true);
curl_setopt($image, CURLOPT_HEADER, 0);
echo '<meta property = "og:image" content = "'.curl_exec($image).'" />';
curl_close($image);
}
</txp:php>
Offline
Re: undefined php tags
Although I can not help in depth but did you try adding a slash before workouts? ie:
$title = curl_init($hopitude_url."/workouts/title/".$wo_id."/".$wo_date."/");
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2018-09-28 10:35:23
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,315
Re: undefined php tags
colak wrote #314201:
Although I can not help in depth but did you try adding a slash before workouts? ie:
$title = curl_init($hopitude_url."/workouts/title/".$wo_id."/".$wo_date."/");...
added three slashes. what it should fix? nothing happened
Offline
Re: undefined php tags
Probably, they should be declared global
in both blocks:
<txp:php>
global $wo_id, $wo_date, $cart_id, $webshop, $hopitude_url;
...
</txp:php>
Offline
#5 2018-09-28 12:35:37
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,315
Re: undefined php tags
etc wrote #314204:
Probably, they should be declared
global
in both blocks:
<txp:php>...
last one Notice: Undefined variable: wo_id while parsing form hopitude on page default
disappeared, but others not.
Offline
Re: undefined php tags
Evidently, if the page URL query does not contain workout=something
, you’ll get a warning. Try to replace all $_GET['...']
with gps('...')
.
Offline
#7 2018-09-29 07:06:14
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,315
Re: undefined php tags
etc wrote #314211:
Evidently, if the page URL query does not contain
workout=something
, you’ll get a warning. Try to replace all$_GET['...']
withgps('...')
.
you were right, errors gone now. corrected block:
<txp:php>
global $wo_id, $wo_date, $cart_id, $webshop, $hopitude_url;
$wo_id = gps('workout');
$wo_date = gps('workoutd');
$cart_id = gps('cartid');
$webshop = gps('webshop');
$hopitude_url = "https://www.hopitude.com/";
</txp:php>
tnx, oleg! let’s see, if everything else (hopitude) working now
Offline
#8 2018-09-29 07:15:08
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,315
Re: undefined php tags
it’s working even without global $wo_id, $wo_date, $cart_id, $webshop, $hopitude_url;
like this:
<txp:php>
$wo_id = gps('workout');
$wo_date = gps('workoutd');
$cart_id = gps('cartid');
$webshop = gps('webshop');
$hopitude_url = "https://www.hopitude.com/";
</txp:php>
do i remove or leave this line in block, what you think?
Offline
Offline
Pages: 1