Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-08-07 16:50:30

richtestani
Plugin Author
Registered: 2009-11-08
Posts: 128

Dynamic Output Form

My first very basic plugin I am adding here. I’ll post the code and the plugin itself.
Its a simple idea of extending the output_form to allow variables within them. I like to think of them as functions with arguments.
Only a valid form name is required.
Hope someone else finds it useful.

  1. Name: rlt_output_form v0.3
  2. Type: Public side plugin
  3. Send your form dynamic arguments
  4. Author: Richard Testani
  5. URL: http://rtest.ws/
  6. Recommended load order: 5
  1. ……………………………………………………………
  2. This is a plugin for Textpattern – http://textpattern.com/
  3. To install: textpattern > admin > plugins
  4. Paste the following text into the ‘Install plugin’ box:
  5. ……………………………………………………………
YToxMTp7czo0OiJuYW1lIjtzOjE1OiJybHRfb3V0cHV0X2Zvcm0iO3M6NjoiYXV0aG9yIjtzOjE1OiJSaWNoYXJkIFRlc3RhbmkiO3M6MTA6ImF1dGhvcl91cmkiO3M6MTY6Imh0dHA6Ly9ydGVzdC53cy8iO3M6NzoidmVyc2lvbiI7czozOiIwLjMiO3M6MTE6ImRlc2NyaXB0aW9uIjtzOjMyOiJTZW5kIHlvdXIgZm9ybSBkeW5hbWljIGFyZ3VtZW50cyI7czo0OiJoZWxwIjtzOjE2NzI6IjxoMT5EeW5hbWljIE91dHB1dCBGb3JtPC9oMT4KPHA+QnVpbGQgZHluYW1pYyBmb3JtcyB1c2luZyBzdGFuZGFyZCB0ZXh0cGF0dGVybiBmb3Jtcy48L3A+CjxwPkNyZWF0ZSBhIGZvcm0gd2l0aCByZXBsYWNhYmxlIHZhbHVlcyB1c2luZyBzdGFuZGFyZCBUZXh0cGF0dGVybiB2YXJpYWJsZXMuPC9wPgo8cD5QYXNzIGluIHRob3NlIHZhcmlhYmxlcyBmcm9tIHRoZSBybHRfb3V0cHV0X2Zvcm0gdGFnIGFzIHN0YW5kYXJkIGF0dHJpYnV0ZXMuPC9wPgo8aDI+RXhhbXBsZTo8L2gyPgo8cCBzdHlsZT0iY29s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S0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0KCSovDQoJJG91dHB1dCA9IG91dHB1dF9mb3JtKGFycmF5KCdmb3JtJz0+JGF0dHNbJ2Zvcm0nXSksICR0aGluZyk7DQoJDQoJLyoNCgkJcmVtb3ZlIHZhcmlhYmxlcyBmcm9tIGV4aXN0ZW5jZSB1bmxlc3MgdGhleSB3ZXJlIHByZXZpb3VzbHkgc2V0DQoJCS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0NCgkqLw0KCWZvcmVhY2goJGF0dHMgYXMgJG5hbWUgPT4gJHZhbHVlKSB7DQoJDQoJCXVuc2V0KCRHTE9CQUxTWyd2YXJpYWJsZSddWyRuYW1lXSk7DQoJCQ0KCQlpZiggYXJyYXlfa2V5X2V4aXN0cygkbmFtZSwgJHJsdF9vcmlnX3ZhcnMpICkgew0KCQkJDQoJCQl2YXJpYWJsZShhcnJheSgnbmFtZScgPT4gJG5hbWUsICd2YWx1ZScgPT4gJHJsdF9vcmlnX3ZhcnNbJG5hbWVdKSk7DQoNCgkJfQ0KCQkNCgkJdW5zZXQoJHJsdF9vcmlnX3ZhcnNbJG5hbWVdKTsNCgkJDQoJfQ0KCQ0KDQoJcmV0dXJuICRvdXRwdXQ7DQoNCn0iO3M6NDoidHlwZSI7czoxOiIwIjtzOjU6Im9yZGVyIjtzOjE6IjUiO3M6NToiZmxhZ3MiO3M6MToiMCI7czozOiJtZDUiO3M6MzI6IjFhNThkMDM3YjkzOGY5NjNmYTM0OTQ2MjA3MDhlZjA0Ijt9

Last edited by richtestani (2012-09-22 16:03:39)

Offline

#2 2012-08-07 17:24:31

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: Dynamic Output Form

Hey, congrats!

Now that you have your own plugin prefix the thing should install. But, alas, it mutters something about bad_plugin_code (TXP probably speaks a bit nicer here, actually, but I’ve just set it to display the core strings). Please have a look at why it does so.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2012-08-07 17:39:59

richtestani
Plugin Author
Registered: 2009-11-08
Posts: 128

Re: Dynamic Output Form

uli, thanks for letting me know – the forum was adding some formatting to the code, so it should be installable now.

Offline

#4 2012-08-07 18:36:38

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: Dynamic Output Form

Alright, now it installs, but the plugin help is malformed (no visible code example), and in ied_plugin_composer there’s no accessible help text, instead there are some duplicated copyright informations and a function. Can’t advise you there, sorry. (The plugin should be named following the function rlt_output_form, BTW.)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2012-08-07 21:23:45

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Dynamic Output Form

This would be a nice feature to have in core…

Offline

#6 2012-08-07 21:41:59

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Dynamic Output Form

Not wanting to hijack the thread nor criticize this new plugin, problem I see with this approach (using txp:variables) is that they remain existing after the form is processed. In other words, the variables are set globally.

It would be could if the created (on-the-fly) variables could be scoped just to the form, as it happens with txp:yield.
I’ve suggested named yields in the past, without success. Artagesw was working on scoped variables but I think that won’t see the light of day any time soon.
smd_macro could be an alternative.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#7 2012-08-07 22:04:29

richtestani
Plugin Author
Registered: 2009-11-08
Posts: 128

Re: Dynamic Output Form

Hi maniqui,

I thought about the global variable issue as well – setting a variable(array(‘name’=>$key, ‘value’=>’‘)) i doubt would unset it.
How do you unset txp variables?

I updated the script to use the correct naming style and added some help and an example.

Offline

#8 2012-08-07 23:22:26

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Dynamic Output Form

There are still issues with your composed plugin package. The code contents that get installed include the actual plugin template. This shouldn’t happen and can causes other issues. For instance error log gets filled by inclusion errors about missing file (zem_tpl.php). How are you compiling the plugins? There is something wrong.

Feature-wise it would be good if it supported yield. You can add yield by passing the functions second argument to the output_form() function as the second parameter.

string output_form( array $atts [ , string $thing=null ] )

You could take a look at the output_form() function to see how $thing is used and what it expects. Which lead to the other thing, missing forms could be let to output_form() to handle instead of retuning a false. The core function will invoke useful error message and all that, which you aren’t and shouldn’t have to. Just call the output_form in any case, it will do the rest.

richtestani wrote:

How do you unset txp variables?

Variables are stored as a global variable named $variable. The variable contains an array map representing the variables used in the tag.

global $variable;
unset($variable['foobar'], $variable['barfoo']);

Take a look at variable() function to see how it’s used. When it comes to clearing the variables, keep in mind that you can’t merely unset them. The plugin will have to keep track of which variables have been set by it, while keeping already set variables safely intact. You should be able to do this by storing the current variables in a temporary variable, which is then used to check which variables where previously set and which weren’t. Those that weren’t are unset and those that were, are restored to their original state.

Last edited by Gocom (2012-08-07 23:25:28)

Offline

#9 2012-08-08 07:12:25

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: Dynamic Output Form

richtestani,

I upgraded you to a plugin author so you can release your plugins in the proper forum


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#10 2012-08-08 18:41:03

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: Dynamic Output Form

Just to mention: that’s what cbe_output_form already does.

Last edited by CeBe (2012-08-08 18:43:07)

Offline

#11 2012-08-12 13:41:55

richtestani
Plugin Author
Registered: 2009-11-08
Posts: 128

Re: Dynamic Output Form

Updated the plugin to support the yield tag, and reset previously set variables of the same name to their original values.
If anyone sees an issues I have missed, please let me know.

Thanks for all the feedback here.
Rich

Last edited by richtestani (2012-08-12 13:42:16)

Offline

#12 2012-08-12 14:21:02

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Dynamic Output Form

richtestani wrote:

If anyone sees an issues I have missed, please let me know.

There is something strange going on with the composed plugin package. The code itself contains the whole plugin template including the help file, <?php tags and and the global plugin array. The plugin file currently contains the following:

Array
(
    [name] => rlt_output_form
    [author] => Richard Testani
    [author_uri] => http://rtest.ws/
    [version] => 0.3
    [description] => Send your form dynamic arguments
    [code] => $plugin['version'] = '0.3';
$plugin['author'] = 'Richard Testani';
$plugin['author_uri'] = 'http://rtest.ws/';
$plugin['description'] = 'Send your form dynamic arguments';
$plugin['type'] = 0; // 0 for regular plugin; 1 if it includes admin-side code
$plugin['name'] = 'rlt_output_form';


if(0) {

?>
# --- BEGIN PLUGIN HELP ---
[ help file ]
# --- END PLUGIN HELP ---
<?php
}
[ plugin's code/function ]
    [type] => 0
    [order] => 5
    [flags] => 0
    [help] => [ help file again ]
    [md5] => 5fdb4534ee643daacd97bb8f82f7cdfe (wondering from what this checksum is).
)

Which all in all, doesn’t seem right. How are you composing/compiling the plugin? I can offer help or suggestions if you have problems.

Offline

Board footer

Powered by FluxBB