Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-06-07 12:53:54

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

etc_post: post anything from the public side

Have you ever needed to edit some txp data (articles, users, etc) on the public side, or even import them automatically from external sources? Then welcome etc_post!

It registers <txp:etc_post /> tag that serves as entry point to the admin side. To give an example, suppose we want to allow the site visitors to submit draft articles in articles section.

  • Create a Freelancer user, say guest.
  • Create an article or rather a custom HTML-type form, say postit:
<txp:etc_post user="guest" event="article" step="save" post="Title, Body, Excerpt, Keywords">
Section=articles
Status=3
publish_now=1
</txp:etc_post>
<txp:header name="Location" value='<txp:site_url />' />
  • Create an article (or even a static web page) with a HTML form like
<form action="?f=postit" method="post">
<input name="Title" placeholder="Title" required="required" /><br />
<input name="Keywords" placeholder="Keywords" /><br />
<textarea name="Body" placeholder="Body"></textarea>
<textarea name="Excerpt" placeholder="Excerpt"></textarea>
<input type="submit" />
</form>

Now everyone can use it to submit draft articles under guest account. Which means use it with much caution :-)

You can also send this form data to ?f=postit via some automated script. And you are not limited to article posting, unlike with some specialized plugins. It suffices to change event and step attributes to trigger any (core or plugin) admin-side action (upload an image, register a new user, etc). The plugin does not write directly to db, but uses the standard txp workflow instead. Enjoy!

Homepage and download.

Offline

#2 2021-06-07 14:20:40

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: etc_post: post anything from the public side

This is simply insane. Love it! Thank you. This is the basis of an import plugin we need since we axed the core feature a few versions ago.

Could the plugin support (hook into?) the Import/TxpXML so we could also import XML files from other CMSs via your plugin?

Or how about CSV somehow one day? Y’know, for completeness ;)

Since it’s event/step based, I guess there’s nothing to stop a companion plugin opening up a new panel on the back-end with a browse… button. Pick file(s) to import – CSV, XML, JSON, INI, … – pick a pre-defined template from a set in your Forms arsenal to squirt the incoming data through (maybe ones with a prefix defined in the plugin’s prefs so there’s some control over which ones are used?) and the data is transmogrified from the input to Txp table data, thrown at your pluign to insert.

Essentially, it’d treat the incoming data stream as a set of delimted records. Pluck out the fields from each record named in the Form, DB-safe them and insert. Repeat. That would neatly handle data mapping too.

And there’s nothing to stop such a companion plugin from offering ‘transforms’ for each chosen field. e.g. split an incoming field into two components, destined for two database columns; combine two or more fields into one database field; pass a field through a textfilter; …

:)

The only thing that would make this even more super awesome would be to insert into more than one table at once. e.g. if someone was to add an image browser, image category and caption fields to an input form (or data stream) then the image would be uploaded, imported, and assigned via ID to the article_image in one step.

That might be a stage too far though as the event/step nature of the plugin would be violated. No biggie to have two panels – one for images, one for articles – and import them separately. The linking would need to be done by hand though.

Or, as I implied above, write a dedicated companion plugin and hook your plugin into its event/step. That way, it could call your plugin multiple times for each incoming file type.

Extremely flexible possibilities!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2021-06-07 15:02:51

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,269
GitHub

Re: etc_post: post anything from the public side

Woah.

Offline

#4 2021-06-07 15:43:12

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

Re: etc_post: post anything from the public side

Thank you, but this plugin is actually too basic to do something by itself. It just posts the supplied data to the admin side, pretending it’s a logged-in user action. As for the data itself, no mapping is done, one needs to provide the exact fields that event/step can handle.

Dunno how it might evolute, but it’s current role is simply to allow for a custom public interface to the admin side.

Bloke wrote #330395:

That might be a stage too far though as the event/step nature of the plugin would be violated.

True, more sophisticated admin-side plugins often make use of JS for data association, and that’s beyond of etc_post abilities, since it acts on the public side.

Or, as I implied above, write a dedicated companion plugin and hook your plugin into its event/step.

That’s actually as companion plugin that etc_post was born :-)

Offline

#5 2021-06-07 15:55:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: etc_post: post anything from the public side

Ha, I forgot about etc_import! I’ll get back in my box.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2021-06-08 16:30:08

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

Re: etc_post: post anything from the public side

Version 0.3 supports CSV format (for completeness, thanks Stef) and requires <txp:php /> privileges (you really shouldn’t put it in anyone’s hands).

BTW, if your favourite text editor supports http posting on save, just create a secret <txp:etc_post /> backdoor, and flat edit you go.

Offline

#7 2021-06-15 18:27:30

Myusername
Member
Registered: 2019-12-12
Posts: 165

Re: etc_post: post anything from the public side

I would like to add some sections, but I was unsuccessful. Can anyone show me how to do this?

Offline

#8 2021-06-15 19:48:31

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

Re: etc_post: post anything from the public side

Myusername wrote #330490:

I would like to add some sections, but I was unsuccessful.

Can you tell us what have you tried?

Offline

#9 2022-11-16 20:51:14

Pemischl
Member
From: Vienna, Austria
Registered: 2012-01-14
Posts: 22
Website

Re: etc_post: post anything from the public side

I tried to replicate etcs example in the first post of this thread, but I am too stupid to make it work for me.

I added an article-form “postit” containing

<txp:etc_post user="guest" event="article" step="save" post="Title, Body, Excerpt, Keywords">
Section=programme
Status=3
publish_now=1
</txp:etc_post>
<txp:header name="Location" value='<txp:site_url />' />

after that i created in content a new article titled “new post” containing:

<form action="?f=postit" method="post">
<input name="Title" placeholder="Title" required="required" /><br />
<input name="Keywords" placeholder="Keywords" /><br />
<textarea name="Body" placeholder="Body"></textarea>
<textarea name="Excerpt" placeholder="Excerpt"></textarea>
<input type="submit" />
</form>

When viewing this article “new post” the form renders, but when submitting it, an empty page “https://(…)/new-post?f=postit” opens and nothing happens in the backend. What am I doing wrong?

Best regards,
Peter

Last edited by Pemischl (2022-11-16 20:52:07)

Offline

#10 2022-11-16 22:21:02

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

Re: etc_post: post anything from the public side

I was curious and gave it a whirl. To begin with I got the same as you. The form in the example will not show anything on the landing page. It should redirect to the home page after completion. However it should post the new article.

I found I had to do exactly as Oleg wrote to make it work: “a custom HTML-type form”

  • Go to Admin › Preferences › Admin and set Advanced options to on.
  • Now visit the new menu item Admin › Preferences › Advanced options and in the textarea Custom form template types add the following:
[html]
mediatype="text/html"
  • Now go to Presentation › Forms and assign postit to the new HTML form type.

Try filling out your form again. You get the blank page (or redirect to homepage) again but now you should see a new article in the Content › Articles list, posted by guest and with a status of Pending.


TXP Builders – finely-crafted code, design and txp

Offline

#11 2022-11-16 23:04:33

Pemischl
Member
From: Vienna, Austria
Registered: 2012-01-14
Posts: 22
Website

Re: etc_post: post anything from the public side

Thank you Jakob! It did the trick.

Offline

#12 2022-11-17 09:50:22

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

Re: etc_post: post anything from the public side

Sorry for the sparse instruction. For the record, ?f=postit is txp URL of a custom type postit form, core forms can not be accessed this way. But nothing stops you from putting <txp:etc_post /> tag in an article or any txp-processed page accessible via internet. Just change ?f=postit to the corresponding URL.

Offline

Board footer

Powered by FluxBB