Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2023-01-17 19:47:47

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

Re: etc_post: post anything from the public side

Thank you! The missing linebreaks did the thing.

Offline

#17 2023-01-17 20:27:38

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

Re: etc_post: post anything from the public side

My next challenge is to change the “Posted” time of a etc_post injected article based on the selection done through a datepicker-input-field. My last (not working) try looks like this.

Form

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

Article

<form action="?f=postit" method="post">
<input name="Posted" placeholder="Date" type="date" required="required" /><br />
<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>

Last edited by Pemischl (2023-01-17 20:34:07)

Offline

#18 2023-01-17 21:38:42

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

Re: etc_post: post anything from the public side

Please look here for the full list of valid article post data.

Offline

#19 2023-01-19 07:55:51

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

Re: etc_post: post anything from the public side

Thanks to etc for the plugin and the hint!
After understanding the plugin, I managed to do it in short time.
Looking into the textpattern core (textpattern/include/txp_article.php) to understand how the article-values are processed, was helpful.

Steps

To insert a custom date I had to:

postit.txp

  • Disable “publish_now = 1” 😔
  • Process year, month, day as input values
  • time (hour, minute, second) are fixed values, so I put them into the ini

Artice form “New Article”

  • select date through an date-input field
  • when changed, extract the values with js and put them into the matching input-fields

Code

html-form postit.txp

<txp:etc_post user="pemischl" event="article" step="save" post="Title, Body, custom_8, Author, Category1, Category2, year, month, day">
  Section=programm 
  Status=4 
  hour=20
  minute=00
  second=00
  Annotate=1
</txp:etc_post>
<txp:header name="Location" value='<txp:site_url />programm/functionality-complete' />

article “Post Article”

<form action="?f=postit" method="post">
    <input name="Title" placeholder="Title"  required="required" /><br />
    <input id="js-date" name="Date"  placeholder="First day of hike" type="date"  required="required" /><br />
    <input id="js-year" name="year" placeholder="Year" /><br />
    <input id="js-month" name="month" placeholder="Month" /><br />
    <input id="js-day" name="day" placeholder="Day" /><br />
    <input type="text" id="js-author" name="Author"><br />
    <select name="Category2">
        <option value="a">A</option>
        <option value="b">B</option>
        <option value="c">C</option>
        <option value="d">D</option>
    </select>
    <input name="custom_8" placeholder="Class Extras" /><br />
    <textarea id="js-body"name="Body" placeholder="Body"></textarea>
    <input type="submit" />
    </form>
    <script>
        const inputDate = document.getElementById('js-date');
        const inputYear = document.getElementById('js-year');
        const inputMonth = document.getElementById('js-month');
        const inputDay = document.getElementById('js-day');
        inputDate.addEventListener('change', function(event){
            let val = event.target.value.replace(/\s.+/,'').split('-');
            inputYear.value = val[0];
            inputMonth.value = val[1];
            inputDay.value = val[2];
        })
    </script>

Todo

I have not managed yet to get a success-page showing a success-message and a link to the posted article or even the article itself.
How do I control the target of etc_post. My tries with with changing the <txp:header /> were not successfull.

Do you have an idea or example where I should look at? Thanks a lot!

Offline

#20 2023-01-19 20:41:42

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

Re: etc_post: post anything from the public side

As you know, etc_post does not alter txp workflow in any way. It just lets you post data from the public to the admin side via a secret door. It can read the answer, but, unfortunately, the latter is badly structured: either a full html admin page or some js code. Extracting what you need is thus cumbersome and beyond the plugin abilities.

But you can try to cheat, retrieving the latest article ID after posting a new (live) article:

<txp:etc_post ... />

<txp:article_custom sort="ID DESC" limit="1">
<txp:header name="Location" value='<txp:permlink' />
<txp:article_custom>

Offline

#21 2023-01-19 21:48:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,477
Website GitHub

Re: etc_post: post anything from the public side

Is there any mileage in making this secret door more official and having it return something more parsable? An API, if you will.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#22 2023-01-20 13:24:17

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

Re: etc_post: post anything from the public side

Bloke wrote #334542:

Is there any mileage in making this secret door more official and having it return something more parsable? An API, if you will.

We have this… among a hundred of other exciting ideas. Sure, accepting/returning a json(-like) data would be cute, but it’s not a few-liner.

Offline

#23 2023-02-23 19:58:18

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

Re: etc_post: post anything from the public side

Is it possible to change the article-author by submitting the AuthorID when using etc_post to submit a new article?

I have tried to submit “AuthorID” or “Author” but had no success.

<txp:etc_post user="pemischl" event="article" step="save" post="Title, Body, custom_8, AuthorID, Category1, Category2, year, month, day">
  Section=programm 
  Status=4 
  hour=20
  minute=00
  second=00
  Annotate=1
</txp:etc_post>
<txp:header name="Location" value='<txp:site_url />programm/functionality-complete' />

Offline

#24 2023-02-23 21:33:34

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

Re: etc_post: post anything from the public side

Pemischl wrote #334737:

Is it possible to change the article-author by submitting the AuthorID when using etc_post to submit a new article?

No, I’m afraid. The only way is to set user attribute to the required AuthorID, but this user must exist and have a recent (<1 or 3 month?) connexion to the admin side.

Recall that etc_post just opens a tunnel from the public to the admin side and then leaves the hand to txp. And txp does not allow changing the author when posting an article.

But you can probably do it in two steps, via two <txp:etc_post /> tags. The first one will publish the article, the second one will change the author via a request like

selected[]=123&edit_method=changeauthor&AuthorID=someone&event=list&step=list_multi_edit

But again, someone must be an existing txp user.

Offline

#25 2023-02-24 14:17:17

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

Re: etc_post: post anything from the public side

Thank you for the hint! I have tried several variations but I still do not fully understand the etc_post logic and could not initiate a change of the Author (the author exists and is active).

V1 fix values for selected[] and AuthorID in tag

<txp:etc_post event="list" step="list_multi_edit" edit_method="changeauthor" selected[]="1894" AuthorID="someone">
</txp:etc_post>

V2 fix values for selected[] and AuthorID enclosed

<txp:etc_post event="list" step="list_multi_edit" edit_method="changeauthor" post="">
   selected[]=1894
   AuthorID=someone
</txp:etc_post>

V3 values for selected[] and AuthorID submitted through form

<txp:etc_post event="list" step="list_multi_edit" edit_method="changeauthor" post="selected[], AuthorID">
</txp:etc_post>

I have no idea what to change and would appreciate every hint.

Best,
Peter

Offline

#26 2023-02-24 18:54:04

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

Re: etc_post: post anything from the public side

The tags own attributes are user, event and step. The rest is populated from $_POST data or from the tags content. You can try this:

<txp:etc_post user="pemishl" event="list" step="list_multi_edit">
edit_method=changeauthor
selected[]=1894
AuthorID=someone
</txp:etc_post>

Offline

#27 2024-06-30 01:54:30

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 36

Re: etc_post: post anything from the public side

I’m trying to post a new article using etc_post. I tried two different ways, using different fields for testing, and in all cases, the article did not post. Also, despite having debugging turned on, there were no errors.

First, I tried:

<form action="<txp:page_url />" method="post">
  <input name="custom_1" placeholder="League Name" value='<txp:page_url type="custom_1" />' required="required" />
  <input name="Title" placeholder="Short Name/Abbreviation" value='<txp:page_url type="Title" />' required="required" />
  <input type="submit" />
</form>

<txp:if_request type="post" name="name" value>
<txp:etc_post user="admin" event="article" step="save" post="custom_1, Title">
Section=articles
Status=3
publish_now=1
</txp:etc_post>
</txp:if_request>

When that failed to post an article, I tried to make my code more like the example etc uses in the plugin documentation. I have a page with this:

<p><h3>New League</h3></p>

<p>
<form action="index.php?f=post_league" method="post">
  <input name="Title" placeholder="League Name" value='<txp:page_url type="Title" />' required="required" />
  <input name="custom_1" placeholder="Short Name (Abbreviation)" value='<txp:page_url type="custom_1" />' required="required" />
  <input type="submit" />
</form>

Then the form post_league’:

<txp:etc_post user="admin" event="article" step="save" post="custom_1, Title">
Section=articles
Status=3
publish_now=1
</txp:etc_post>
<txp:header name="Location" value='<txp:site_url />' />

Same results: the form displays, there is no error with submission, but the article does not post. I’ve tried different fields, I’ve tried switching around the order of posted fields, but no dice. I’m using 4.9.0 Dev. If anyone has any thoughts… Thanks!

Last edited by ironmangary (2024-06-30 03:13:41)

Offline

#28 2024-06-30 08:05:51

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

Re: etc_post: post anything from the public side

Make sure first that admin user exists and has been recently (like within 3 month) logged in.

In your example, the form does not contain name input, so <txp:if_request type="post" name="name" value /> block is not processed.

You can try adding debug="r" attribute to <txp:etc_post /> to see what server responds to the plugin’s request. Don’t hesitate to come back if it does not help.

Offline

#29 2024-07-01 01:45:37

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 36

Re: etc_post: post anything from the public side

It was the bad <txp:if_request /> tag values. Works great now. Thank you!

Offline

#30 2024-07-08 15:32:48

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 36

Re: etc_post: post anything from the public side

I have a follow up issue. After getting the new article to post, I decided to create a form to allow users to edit the articles they’ve created. Here’s the form code:

<form action="<txp:page_url />" method="post">
<input type="hidden" name="action" value="save_league_edits" />
<label for="custom_1">League Name</label>
<input type="text" id="custom_1" name="custom_1" value='<txp:custom_field name="league_name" />' maxlength="30" size="30" required />

<label for="Title">Short Name/Abbreviation</label>
<input type="text" id="Title" name="Title" value='<txp:title />' maxlength="10" size="10" required />

<label for="custom_20">League Logo (URL - only .jpg or .gif)</label>
<input type="text" id="custom_20" name="custom_20" value='<txp:custom_field name="image_url" />' pattern=".*\.(jpg|gif)$" />

<label for="custom_2">League Owner or Fed Head</label>
<input type="text" name="custom_2" id="custom_2" value='<txp:custom_field name="league_ceo" />' maxlength="30" size="30" />

<label for="custom_3">Headquarters</label>
<input type="text" name="custom_3" id="custom_3" value='<txp:custom_field name="league_hq" />' maxlength="30" size="30" />

<label for="Body">League Description</label>
<input type="textarea" id="Body" name="Body" cols="60" rows="20" value='<txp:body />' />

  <input type="submit" value="Update League" />
</form>

<txp:if_request type="post" name="action" value="save_league_edits">
<txp:etc_post user="admin" event="article" step="save" post="custom_1, Title, custom_20, custom_2, custom_3, Body">
category1=league
Section=test
Status=4
publish_now=1
</txp:etc_post>
</txp:if_request>

The page pulls up the desired info, populating the HTML form perfectly. However, after I modify the form and click Update, the data is not updated. There are no errors and I am using the “admin” user to avoid any permissions issue, as this is my main user account. For the step, I have tried both “save” and “edit”. I’m not sure what I’m doing wrong.

Offline

Board footer

Powered by FluxBB