Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-05-12 21:07:52

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 259
Website

Literally displaying the code of a form

I need to build a ‘Pattern Library’ to help in the management of a large 4.7.3 site.

I’m looking to rationalise my Forms in TXP so that staff can make better use of the ‘Override Form’ feature; a section on the site which acts as a visual library of all the various forms (and their associated code).

The ‘associated code’ bit is where I’m stuck.

How do you ‘inline code’ the contents of a form?

eg. calling on plainlinks.txp would output
<txp:linkdesctitle rel="external" />

Thanks!

Last edited by giz (2019-05-12 21:09:42)

Offline

#2 2019-05-12 22:03:28

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: Literally displaying the code of a form

Interesting question.

There’s likely a better way, but presumably you could leverage textpattern’s safe_field function inside txp:php to retrieve the contents of the form code field from the database. If you want to pass the form name to it from outside the txp:php block, you could set that in advance as a variable, and then use that in your php code, e.g.:

<txp:variable name="form_name" value="my_form" />
<txp:php>
    global $variable; 
    echo safe_field(
        'form', 
        'txp_form', 
        "name = '".doSlash($variable['form_name'])."' AND skin = 'your_theme_name'"
    );
</txp:php>

(replacing your_theme_name with the theme you are using)

It’s likely you might want to iterate over a list of predefined form names. For that you could use rah_repeat or smd_each to populate the variable.

However, is it really the txp tag code you want to show your users or rather the html widget it produces?

If the latter, see what happens if you use the regular txp:output_form tag inside pre and/or code html tags. With a bit of luck, you should get the html code rendered in a code block…


TXP Builders – finely-crafted code, design and txp

Offline

#3 2019-05-13 07:36:37

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Literally displaying the code of a form

There is no preset way to output forms content, due to privacy restrictions (forms can contain <txp:password_protect /> and other sensible information). However, you can

  • enable fetch_form() function for use in <txp:evaluate /> via advanced prefs;
  • call <txp:evaluate query='fetch_form("my_form")' escape wraptag="pre" />.

If needed, my_form parameter can be passed via <txp:variable /> or <txp:yield />.

Offline

#4 2019-05-13 18:11:26

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 259
Website

Re: Literally displaying the code of a form

Thanks Jakob & Oleg.

Offline

Board footer

Powered by FluxBB