[Resolved] how should I do to create new post with form?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by francescoG-3 4 months, 4 weeks ago.

Assigned support staff: Luo Yang.

Author
Posts
#1506061

Tell us what you are trying to do? I need to create new posts using Form link. (I'm using the Block Editor in Content Template)
I have created a form to create new posts, I have created a content template where I have added the "Add new post" Form shortcode. Also, I have created and added the form and the shortcode to edit the posts.
I have created a View to generate the Delete Post link.
Well, in the sidebar, now, I have created a section to display the links to open the relative form page.
Then, the Edit Post work fine and the shortcode is [toolset-edit-post-link content_template_slug='modifica-evento']<i class="fas fa-pen-square"> Modifica Evento[/toolset-edit-post-link]
The Delete Post link work fine.

To add "Add New Post" link I have tried two solutions but I don't know if they are correct...
First solution: I have used the following shortcode [toolset-edit-post-link content_template_slug='nuovo-evento-add']<i class="fas fa-plus-square"> Aggiungi Evento[/toolset-edit-post-link], this shortcode open the correct form page, but the url contain the name of the post from where I have clicked the link, and I think that it is not the correct method...

Second solution: I have create a page and I have assigned to it the "Add New Post" Content Template. After I have created a Text Block in the section, and I have opened the Form Box and I have 3 sections, the first display the "Create" forms, the second display the "Edit" forms, and the third display "Other Actions" where there are the buttons to generate the links to edit, delete, create the posts, etc...
Well, the button to add the "Add New" link display this text in Italian "Crea il link dell'articolo figlio" (Create the Child Post link), now, I don't need the link to create "child" posts, but I need the link to create the "parent" posts...

What should I do to do that?

Is there any documentation that you are following? I'm searching for it but I don't have found anything...

Is there a similar example that we can see? I don't know...

What is the link to your site? hidden link

And what should I do to not display the "?cred_referrer_form_id=76589" in the posts URLs?

#1506585

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hello,

Yes, I agree with you, I think the second solution is in right way.

I assume we are talking about two post types:
- Parent CPT
- Child CPT
One-to-many relationship between "Parent CPT" and "Child CPT"
You are going to do these:
1) In a single "Child CPT" post, for example: POST A, display a HTML link,
2) User click above link, goto a page (PAGE C, id 123) with a post form for creating new "Parent CPT",
3) User submit above post form:
- New Parent CPT created, for example: POST B
- Setup one-to-many relationship between posts "POST B" and "POST A"

If it is, there isn't such kind of built-in feature, it will need custom codes.
Here are my suggestions:
1) In single "Child CPT" post, you can setup the HTML link:
- link to "PAGE C"
- pass the current "Child CPT" post ID as URL parameter "child-id", for example:

<a href="[wpv-post-url item='123']?child-id=[wpv-post-id]">Add a parent post</a>

2) In "PAGE C", display the post form for creating new parent post.

3) in above post form content, you can get the URL parameter "child-id" value, like this:

[wpv-search-term param="child-id"]

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-search-term

Use above shortcode as default value of hidden field:

[cred_generic_field type='hidden' field='child-id']
{
"default":"[wpv-search-term param="child-id"]"
}
[/cred_generic_field]

https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/#cred_generic_field

4) After user submit above form, use action hook cred_save_data to trigger a PHP function, in this PHP function:
- Get the hidden field "child-id" value
hidden link
- Use above value to setup relationship with function "toolset_connect_posts"
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

More help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
This hook allows doing a custom action when post data is saved to database

For your reference.

#1506847

Hi Luo,
Sorry, I think I do not explain my problem correctly.
We are talking about the native WordPress Post Type, without any relationship and child post type.

I need only to have a link to Add New Post using Form.

#1508083

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

For the question:
I need only to have a link to Add New Post using Form.

You just need these:
1) create a new page, for example, page ID is 123
2) In above page, display a Toolset form for creating post
3) Display the add new post form link, linke this:

<a href="[wpv-post-url item='123']">Create new post</a>

https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/

#1509085

Ok, it works fine. Thank you