Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2008-07-26 11:32:36
- ahlt
- New Member
- Registered: 2008-06-19
- Posts: 5
Call a form from a plugin file
Hi, I’ve been playing with Textpattern for a while now, but recently stumbled upon a problem.
I’ve created a plugin which prints out posts from a phpbb3 thread. I want the user to be able to style this information before it’s printed out, therefor I created a custom form. But I don’t know how to call this particular form from my plugin file?
I’m running a cycle trough a array which contains all information about the thread, and would like the form to be called for each individual post in that thread.
Hope you understand what I mean, and thanks for any input: )
Offline
#2 2008-07-26 13:21:21
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Call a form from a plugin file
ahlt
Hello, I’ll take a shot at answering your post but I’m going to be making some assumptions as you don’t mention your data format or if your plugin provides new tags for use in the styling form to pull the values or if you are looking for a way to replace some kind of token in the styling form.
I mean something like (tags)…
<div class="my_plugin_post">
<h2><txp:my_plugin_poster_name /></h2>
<p><txp:my_plugin_poster_message /></p>
</div>
…vs (tokens)…
<div class="my_plugin_post">
<h2>{name}</h2>
<p>{message}</p>
</div>
In the tags case you are going to need to call textpattern’s parse_form('your_form_name')
routine.
In the tokens case you are going to need to call textpattern’s fetch_form('your_form_name')
routine and then do your own token replacements.
For tags, your main routine would need to setup the context for each parsing of the style form by pulling the current phpbb post into a global that each tag would access to output data. Something like…
global $phpbb_post;
$out = array();
foreach( $phpbb_thread as $phpbb_post )
{
$out[] = parse_form('your_form_name');
}
echo join( n , $out );
Each of your tags would then access the $phpbb_post global to grab some part of it for display. Or you could have a generic tag that took an argument telling it which bit of the post to output.
For tokens, how about something like…
$form = fetch_form('your_form_name');
$out = array();
foreach( $phpbb_thread as $phpbb_post )
{
$out[] = parse( strtr( $form , $phpbb_post ) );
}
echo join( n , $out );
This would need the $phpbb_post data to be setup as '{name}'=>'value'
entries that match the token names used in your form. If they were not so matched then you’d have a little more work to do getting them in the right format..
As an example from a live plugin, here’s how I do a tokenised form from sed_pcf
if( !empty( $form ) ) # grab the form (if any)
$thing = fetch_form($form);
$out = array();
$field = do_list( $field );
foreach( $field as $value )
{
$out[] = parse( str_replace( '{value}' , $value , $thing ) );
}
return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class);
Hope that helps.
— Steve
Offline
Re: Call a form from a plugin file
echo parse(fetch_form('form_name'));
You can optimize it, like fetching the form only once and then call it for differents “items”, but this is the way.
Offline
Re: Call a form from a plugin file
Yep, the form can be output with various of ways – er different core functions that basically do the same queries: fetch_form(), fetch(), safe_field() etc. And if you want to parse it, aka show TXP-tags inside of it, then the only thing you need, is parse()
.
And to add what txp tags are: basically functions inside your plugin. Steve’s explenation is very good to explain some of it :) In example if you want to make post_title
tag, then just make a function that returns the post title etc.
Offline
Pages: 1