Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to include a Textpattern form into an external PHP page?
I was wondering whether it is possible to include a form from Textpattern into an ‘external’ php document at the root of my domain.
For those wondering why I want to do this: I could use upm_image inside the Textpattern form to fetch all images from a category, and parse those into xml format so that Simpleviewer can display them.
(It is already possible to pair simpleviewer with textpattern, yet up to now it only gets all images. I only need those from a specific category.)
Last edited by dl33 (2007-12-29 17:26:13)
Offline
Re: How to include a Textpattern form into an external PHP page?
A floating commenter suggested getting the form from the txp_forms table. This was also my first thought yet one problem with this might to be that I will get the unparsed version of the form.
I need the parsed version with all images links in it… (I am trying to generate a xml file for SimpleViewer, which is then included into the real xml file at the root of my domain.)
Last edited by dl33 (2007-12-29 17:39:23)
Offline
Re: How to include a Textpattern form into an external PHP page?
From a high level perspective, Textpattern provides two subroutines you’d have to call from your own PHP script:
- fetch_form() fetches a named from from the database
- parse() parses a form and returns the equivalent HTML
Therefore, you’d have to include at least ../textpattern/publish.php, probably more.
Offline
Re: How to include a Textpattern form into an external PHP page?
Thanks for the help, wet. I’ll give that a try. Do you know who I have to ask in order to find out what files I have to include?
Offline
Re: How to include a Textpattern form into an external PHP page?
You wouldn’t need to ask anyone, just enable PHP’s error reporting, wait for error messages to pop up and look up the missing functions in Bert’s PHP-Xref for Textpattern.
Offline
Re: How to include a Textpattern form into an external PHP page?
thanks…
Offline
Re: How to include a Textpattern form into an external PHP page?
hi
maybe I’m misunderstanding your question…but I am using a textpattern form on an external php page on my website and it’s working pretty well. The way I’m doing it is
- create a section which uses a page template called “pictures” for example;
- in the page template pictures, i have code that outputs a form using <txp:output_form form=“formname” />. The form could have anything you want including upm_image statements.
- in the external php page, I use a REQUIRE or an INCLUDE statement that will include the output for the form.
Would’nt this work for your particular instance too or am I missing something?
Regards
Last edited by JonahC (2007-12-31 04:56:21)
Jonah Calinawan
www.foodportraits.com
Offline
Re: How to include a Textpattern form into an external PHP page?
Hi JonahC,
I think that your example would work in my case. I haven’t actually got around to implementing anything so could you post some of your code? (My PHP Knowledge is not that great; it saves me looking up an each and every function.)
However I think I might get better results if I choose to embed the form directly, instead of embedding a page which has an embedded form…
Thanks,
dl33
Offline
Re: How to include a Textpattern form into an external PHP page?
I ended up using JonahC’s technique, as it is a lot easier. However, I am still struggling to tell Simpleviewer about the xml file. (I use the free version.)
Is there an easy way to load /xml when /gallery.xml is called. I was thinking of a .htaccess rewrite, however, there might also be a php solution. The important bit is that it is fully automated and instant.
I tried modyfying .htaccess myself. This is what I came up with up to now, and of course it is not working. Any ideas.
DirectoryIndex index.php index.html
Options +FollowSymLinks
RewriteBase /
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !^/gallery.xml$
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.*) index.php
RewriteRule ^/gallery\.xml$ /xml [L]
</IfModule>
Last edited by dl33 (2008-01-02 15:11:31)
Offline
Re: How to include a Textpattern form into an external PHP page?
Hi dl33-
Sorry for not responding sooner as I was away for New Years. I debated whether I should post a reply to this thread as I think it’s way over my head, but I decided to post this anyway in case there’s something here you can use. :)
Now that I understand what you are trying to do, I’m not so sure now whether you can do what you want with textpattern. For example, how are you dealing with the thumbnails? In textpattern, the thumbnails are in the same folder as the main images and the thumbnail name has a “t” in the end. I think Simpleviewer requires separate folders, right? I’m actually using another flash program called Autoviewer which is also written by Felix Turner and the code is similar to Simpleviewer.
Anyways, I’d like to help so assuming there are no problems with thumbnails here’s example code on how I included textpattern form in an external php or html page. I’m not an expert at php either, but I got it to work at least on my website. :)
My portfolio page which is an external page uses a textpattern form. This form is called from this external page using the following code:
<?php require($DOCUMENT_ROOT . "http://foodportraits.com/sidebar/"); ?>
“Sidebar” is a section in textpattern that I created which uses a page template that only has the following code in it:
<div id="sidebar"> <txp:output_form form="jrc_sidebar" /> </div><!-- closes sidebar div -->
The form jrc_sidebar has the following code:
<div class="sitename"> <a rel="home" href="http://foodportraits.com/">foodportraits.com</a> </div> <div class="slogan"> photography for the food industry & your kitchen </div> etc. etc. etc.
So I’m wondering whether you can do something like this…
1. Have a textpattern page with all the links to all images grouped by category like
http://yoursite.com/section/?c=vacationphotos
http://yoursite.com/section/?c=portraits
you can probably use something like rss_superarchive plugin to generate the page with all the links. Have a look at my food category archive as an example. One of the options in the rss_superarchive plugin is the “go to” section when a link is clicked. You could set the section to go to the simpleviewer section which uses a page template that has the simpleviewer
html code as provided in the zip file. Call this page template “viewerpage.”
I guess what I’m saying is that you don’t need an external file for the simpleviewer html code – textpattern could manage that too.
2. In the <body> section of the “viewerpage” page template, instead of
fo.addVariable("xmlDataPath", "gallery.xml");
you could have
fo.addVariable("xmlDataPath", "http://yoursite.com/imagelist/?c=<txp:php>echo $_GET['c'];</txp:php>");
According to the data customatization options, the XML data source can be an XML document, or a script that produces an XML document — so it doesn’t have to be an xml file. The xmlDataPath is an absolute or relative path to an XML data source – (you might have to play around with the paths).
The category in the xmlDataPath will be dynamic depending on what link was clicked in step #1.
3. Imagelist is yet another textpattern section which will replace the xml file. This section uses a page template called “categorylist” which will contain the gallery.xml code from the zip file.
<?xml version=“1.0” encoding=“UTF-8”?>
<simpleviewerGallery maxImageWidth=“480” maxImageHeight=“480” textColor=“0xFFFFFF” frameColor=“0xffffff” frameWidth=“20” stagePadding=“40” thumbnailColumns=“3” thumbnailRows=“3” navPosition=“left” title=“SimpleViewer Title” enableRightClickOpen=“true”
backgroundImagePath=”“ imagePath=”“ thumbPath=”“>
<txp:wet_for_each_image break=“image” />
<filename><txp:upm_img_name escape=“html” /></filename>
<caption><txp:upm_img_caption escape=“html” /></caption>
</txp:wet_for_each_image>
It seems that the plugin wet_for_each_image automatically picks the category in the url according to this page. If not, then you could always include that as an attribute which can be dynamic depending on what category is being called in the url.
Could something like this work?
Last edited by JonahC (2008-01-03 05:11:30)
Jonah Calinawan
www.foodportraits.com
Offline
Re: How to include a Textpattern form into an external PHP page?
JonahC: You are awesome:) I didn’t know that you could specify a custom xml datapath for Simpleviewer. (At least not for the free version.) That was pretty much the missing link.
Once I get everything working, I’ll post a short summary on how I got it working, even though I think you pretty much hit the nail on the head.
Offline
Re: How to include a Textpattern form into an external PHP page?
JonahC wrote:
<?php require($DOCUMENT_ROOT . "http://foodportraits.com/sidebar/"); ?>
I like this and started using it to unify some common content between neme.org and neme-imca.org. The problem is that when there is an error the whole site fails
Is there a way for errors to be suppressed if the section is unavailable?
Last edited by colak (2008-01-24 15:26:38)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline