Reference library

Article number: 305419

More posts extensions

In addition to the web service interactions referenced in extending posts. Posts can also be edited deleted and modified programmatically by making additions to the relevant query string or form post fields.

Examples of use cases for this would be adding fields to a post via a form or button or using a link to delete a specific post. The action argument can also be daisy chained to allow multiples in the one submission. eg

<Input type="hidden" name="action" value="updatepost,addpostfieldvalue"/>

Note that only the owner of the post can update it from the front-end.

Edit post

A front-end form can be populated with field values from an existing post using javascript/ajax or an XML Data Island. The user can edit the values of posts that they are the owner of and, when the form is submitted, the post will be updated with the changes made.

For this to work, the form fields must match field names in the post type using the following naming convention:

Field Name Value Description
action updatepost The form must have a hidden field called 'action' with the value of 'updatepost'.
editpostid <postid> The form must have a hidden field called 'editpostid' with the post id of the post to be updated.
name <value>  Use a field name of 'name' if you want to update the name of the post.
body <value>  Use a field name of 'body' if you want to update the main body content of the post.
startdate <value> Changes the start date. The value accepts most standard date/time formats, e.g. 2022-12-25 09:00.
enddate <value> Changes the end date. The value accepts most standard date/time formats, e.g. 2022-12-25 09:00.
custom_<fieldname> <value> If you want to update the value of a custom field in the post use its name prefixed with 'custom_', e.g. if the field in the post type is called 'telephone' then use 'custom_telephone' as the form field name.
custom_inc_<fieldname> 1 or -1 If you want increment or decrement the value of an integer field you can use a field prefixed with 'custom_inc' and the corresponding post field will have its value incremented or decremented.

Only include form fields for values you want to update. It is not necessary to include a form field for every field that the post type has.

The form must be submitted using POST not GET.

When using the Sitekit Forms Module to design your form, you must make sure that the form is a type 1 or 2 form. Do not use this with type 3 forms. 

Delete post

A post can be deleted using a querystring parameter or form field called 'deletepostid' whose value is the post id of the post to be deleted.

Field Name Value Description
deletepostid <postid> The form or querystring must have a field called 'deletepostid' with the post id of the post to be deleted.

The user can only delete posts that they created.

Amending 'List' Type Post Fields

It is possible to modify 'list' type post fields using form fields with the following naming convention. An example of a post list field would be a field called 'fruit', which could have values 'Apples,Pears,Oranges' and you want to say add 'Plums' or remove 'Pears'.

Field Name Value Description
action addpostfieldvalue  
updatepostid <postid> The post id of the post to be updated.
postfieldname <postfieldname> The name of the field that you want to update.
postfieldvalue <value> The value that you want to add to the list that is held in the field.

 

Field Name Value Description
action removepostfieldvalue  
updatepostid <postid> The post id of the post to be updated.
postfieldname <postfieldname> The name of the field that you want to update.
postfieldvalue <value> The value that you want to remove from the list that is held in the field.

 

Related questions