Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-11-01 12:01:41

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

Create new content with pre-filled fields, configured by URL parameter

This may smell strongly of plugin territory and/or edge case – here for RFC nonetheless.

I’m in a position where I want to create a new article with a post-dated publication date. It’s for a journal / blog type of setup, the gist being multiple updates / edits can be made over the day, and the article goes live a set time (e.g. 23:59 local time for that day). I’d really love to be able to sanely (and safely) pre-fill some fields with dynamic information:

  • date & time of publication (using date(), epoch or similar)
  • title (using date(), percent encoded)
  • section, category1 and category2
  • status

A new article is created with this syntax:

https://example.com/textpattern/index.php?event=article

Something like this is what I have in mind:

https://example.com/textpattern/index.php?event=article&title=Monday%2C%20January%201%202022&section=lorem&category1=ipsum&posted=1640995200

…and so on. URL parameters follow the SQL syntax, with whatever escaping and safety nets need to be implemented.

To be clear: I’m not asking for a way to do all the shopping list above and pre-fill it, just how viable it might be to offer the parameterised approach as a basic API. I can construct a hidden page with dynamic links to profile the field content, and construct the URL accordingly.

Thanks for reading, I’d appreciate any advice on how viable this may be.

Offline

#2 2021-11-01 15:14:39

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

Re: Create new content with pre-filled fields, configured by URL parameter

If you don’t mind constructing a ‘catch’ page somewhere (admin side via smd_tabber, or public side if you suitably obfuscate the URL) then you could maybe use etc_query to achieve that. I’d suggest smd_query too, but etc_query is far more capable. But either of those plugins can capture URL params and construct a DB query from them.

The downside is it won’t instantly transport you to the Write panel so you can actually start editing – it’s an offline task that will create the empty article with the given params and then you can click to edit it from the Articles panel as normal.

If you’re using smd_tabber you have greater scope for a dashboard type of thing. You could set it up so you can have a bunch of form fields you fill in, which will then construct the URL params for you.

On submission of those form fields, smd/etc_query takes over, creates the empty article and, once it’s retrieved the new ID, can then forward you straight to the Write panel for immediate editing.

It largely depends on your workflow and whether this is a batch automation job or an on-demand thing. And also depends if you’re operating it and don’t mind it looking a bit Blue Peter vs making it more polished so a client can create their own pre-filled articles.

Lots of approaches but, yes, requires a plugin I expect. At least at the moment.

EDIT: When creating articles, we do have the concept of a ‘store’ – a blob of content from all form fields passed in ready to repopulate the database each time you hit Save. We might be able to open that up so it’s available on first submission rather than only after first save or make the panel respond to URL input on for new content.

Last edited by Bloke (2021-11-01 15:18:01)


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-11-01 15:19:34

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

Re: Create new content with pre-filled fields, configured by URL parameter

Brilliant. Many thanks, señor.

Offline

#4 2021-11-01 21:29:01

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

Re: Create new content with pre-filled fields, configured by URL parameter

You might want to consider etc_post, though it uses $_POST (and not $_GET) to pre-fill fields.

Offline

#5 2021-11-02 08:14:43

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

Re: Create new content with pre-filled fields, configured by URL parameter

etc wrote #331882:

You might want to consider etc_post

Oh, I’d forgotten about that! Thanks for the reminder, etc!

Offline

Board footer

Powered by FluxBB