The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.28 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.28 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.28 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.28 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.28 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.28 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.28 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.28 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.28 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.28 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.28 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.28 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.28 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.28 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
PHP & Smarty in Pages Module - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Modules / Other (https://forums.formtools.org/forumdisplay.php?fid=8)
+--- Forum: Modules (https://forums.formtools.org/forumdisplay.php?fid=16)
+--- Thread: PHP & Smarty in Pages Module (/showthread.php?tid=1603)



PHP & Smarty in Pages Module - tosuch - Sep 7th, 2011

Using Formtools core 2.1.1 and Pages module 1.2.4.

I wonder if there is some sample PHP code and Smarty code that I could try in the Pages module as when I use HTML tags all works OK.

However, when I move to trying PHP and enter code (have tried with and without the opening and closing PHP tags I get a blank page).

Grateful if you could let me know if I am doing something incorrectly or if there is something that needs to be checked in the Pages module.

Ted


RE: PHP & Smarty in Pages Module - Ben - Sep 8th, 2011

Hi Ted,

Interesting! Could you post the PHP you're entering?

It should be entered without the opening and closing tags: the entire block is simply eval()'d as PHP, so no tags are necessary.

I just tested it out and it appears to be working okay. If there's any syntax error in the code, nothing will appear. To confirm that it's working (the evaluation of the PHP code, at least), try creating a page with this content.

PHP Code:
echo "Hello world."

Assuming that that page output's "Hello world", then at least we know the code is being parsed.

Let me know how it goes!

- Ben


RE: PHP & Smarty in Pages Module - tosuch - Sep 9th, 2011

Ben,

Thanks for the sign posts.

As you stated:

1. If there is ANY syntax error then nothing appears. The simple echo example works.

2. Also I was trying to use the API and my path was incorrect to the global/api directory. Once I fixed the path I was able to pull data from the database.

Also goes to show that you need to think PHP when in PHP mode in the Pages module. I know that sounds obvious but it wasn't when I asked the question.

I have now managed to use the API to show some useful content from the database in pages directly in the UI - this is cool for customers and can be used to build some very powerful reporting. So I am off to get some more PHP code.

I would like to post a short tutorial on this feature - if you like - in the next week or two based on my findings. Its amazing what a little knowledge can lead to.

Finally - and it's not urgent - but would help (and maybe lead to another tutorial) - do you have a few lines of Smarty code I could use to check out how the Smarty mode works? I will then go off to Smarty world (web site) and find out what can be done from there.

Once again thanks a lot for your help.

Regards

Ted


RE: PHP & Smarty in Pages Module - Ben - Sep 10th, 2011

Quote:I would like to post a short tutorial on this feature - if you like - in the next week or two based on my findings. Its amazing what a little knowledge can lead to.

That would be terrific!

The Smarty + PHP options in the Pages modules have been very helpful for my own work: you can call any smarty template or Form Tools code directly there, so it's really cut down on development time (no more manual creation of pages containing custom logic). But speaking candidly, the PHP + Smarty feature isn't well documented simply because most people don't delve that deep, so my time has been focused elsewhere.

Quote:Finally - and it's not urgent - but would help (and maybe lead to another tutorial) - do you have a few lines of Smarty code I could use to check out how the Smarty mode works? I will then go off to Smarty world (web site) and find out what can be done from there.

Sure! For starters, take a look at the contents of the /global/smarty/plugins folder. That folder contains a whole bunch of Form Tools-specific functions for use in Smarty pages. Those are what's used throughout the actual Form Tools pages to display chunks of code, like dropdown lists of forms, Views, option lists etc.

As a simple example, the following will output a dropdown list of all forms, followed by a dropdown of all clients.

Code:
Forms: {forms_dropdown name_id="forms"}<br />
Clients: {clients_dropdown name_id="clients"}

It's a crude example, because that information won't be very useful in of itself. But you can build on that to (for example) auto-redirect to the appropriate form page or edit client page after an option is selected. To do that, you'd add an onchange parameter to each.

Code:
Forms: {forms_dropdown name_id="forms" onchange="alert(this.value)"}<br />
Clients: {clients_dropdown name_id="clients" onchange="alert(this.value)"}

(I just did the alert for example purposes). Each Smarty function allows for different parameters, so it's a matter of sifting through the different functions to see what additional parameters are available.

Hope that gives you an idea... Anyway, good luck! Smile

- Ben