Skip Navigation

[Resolved] Possibility of “Save” and also “Send and Close” button in Content form

This thread is resolved. Here is a description of the problem and solution.

Problem:

Add a "Close and Send" button in Toolset post form.

Solution:

If it is, there isn't such a built-in feature within Toolset form, but it is possible within some custom PHP codes, for example:

https://toolset.com/forums/topic/possibility-of-save-and-also-send-and-close-button-in-content-form/#post-1071304

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

100% of people find this useful.

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 9 replies, has 2 voices.

Last updated by jiriK-2 6 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1070234

Hello,

I'm building up Toolset Content Form, here's the link of the screenshot: hidden link

I would like having not only "Uložit" (Save) button but also "Close and Send" button:

1. "Save" button means saving for future editing
2. "Close and Send" button means finishing editing the form and sending it for approval – the form will not able to be visible and editable again for the user.

How to make it with Toolset?

Thanks for your help, best,

Jiri.

#1071243

Dear Jiri,

I assume we are talking about a Toolset post form for creating new post, you are going to allow each user can create only one post.

I suggest you try this:
1) Create a view list posts, whose author is current user
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

2) if there is any result found, display a message, for example, your post is waiting for approval
if there isn't any result found, display the Toolset form for creating new post
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-no-items-found

Then after user submit the form, redirect him back to the view, his post exists in your website, he will not be able to see the Toolset form again.

#1071272

Dear Luo Lang,

thank you for your reply,

in fact, there is no need for the user to see the list view of the post – it is a competition and when the user will click on "Send and Close" button then he/she is not going to see his post anymore - only me as the administrator and other contributors to evaluate all the application forms later.

That's why I was trying to explain a function of these post's buttons:

1. "Save" button means saving for future editing – BUT there is going to be a deadline for sending and closing of the application form post.

2. "Close and Send" button means finishing of editing the application form NOW and sending it for approval – the form will not able to be visible and editable again for the user after this closing and sending.

Many thanks for your suggestion and help.

Best,

Jiri.

#1071304

Thanks for the details, I assume you are going to have two different submit buttons in the same Toolset form for editing the post:
"Save" button + "Close and Send" button, different button does different job as you mentioned above.

If it is, there isn't such a built-in feature within Toolset form, but it is possible within some custom PHP codes, for example:
1) Put two different submit buttons into your Toolset form for editing the post.

	[cred_field field='form_submit' value='Save' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
	[cred_field field='form_submit' value='Close and Send' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

When user click different button, it will pass different PHP POST variable to the Toolset form, for example:
'form_submit_1' => 'Save'
'form_submit_2' => 'Close and Send'

2) Use action hook cred_save_data to trigger a custom PHP function
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

In this function check which button your user clicked, if it is "Close and Send" button, update a custom field "closed" value to "closed".
https://codex.wordpress.org/Function_Reference/update_post_meta

3) In the front-end use [wpv-condition] shortcode to check the custom field "closed" value, if it is closed then don't display the Toolset form.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#1071400

Dear Luo Yang,

many thanks again for your suggestion,

I'm going to follow your recommendation and I will let you know about the result.

Thanks again, best,

Jiri.

#1071417

Dear Luo Lang,

I was able to put these two different submit buttons in my form

[cred_field field='form_submit' value='Save' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
[cred_field field='form_submit' value='Close and Send' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

please look here:

hidden link

but the rest is too complicated for me....

2) Use action hook cred_save_data to trigger a custom PHP function
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

In this function check which button your user clicked, if it is "Close and Send" button, update a custom field "closed" value to "closed".
https://codex.wordpress.org/Function_Reference/update_post_meta

3) In the front-end use [wpv-condition] shortcode to check the custom field "closed" value, if it is closed then don't display the Toolset form.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

Please could you be more specific about these functions?

Many thanks,

Jiri.

#1072350

Since it is a custom PHP codes problem, please provide a test site with the same problem, and fill below private message box with credentials and FTP access, also point out the problem page URL and Toolset form URL, and where I can edit your PHP codes, I need a live website to test and debug in a live website

#1072518

Thanks for the details, I have done below modification in your website:
1) Edit the Toolset post form "Projekty"
hidden link

Change it from option "Add new content" to "Edit existing content"

2) Edit the post field group "Projekty Field Group", add a checkbox field "Closed":
hidden link

3) Edit your theme file "functions.php", add below PHP codes:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==166)
    {
		// "Close and Send" button clicked
        if (isset($_POST['form_submit_2']) && $_POST['form_submit_2'] == 'Uzavřít a odeslat')
        {
            // saved post meta
            update_post_meta($post_id, 'wpcf-closed', 1);
        }
    }
}

4) Create a layout "Edit Projekty", put above Toolset form into it
hidden link

5) Edit the layout "Template for Projekty"
hidden link

In the first row, visual editor cell, add below codes to display the edit link:

<p>[wpv-conditional if="( $(wpcf-closed) eq '1' )"]
This post is closed, you can not edit it anymore
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-closed) eq '1' )" evaluate="false"]
[toolset-edit-post-link layout_slug="edit"]Edit %%POST_TITLE%%[/toolset-edit-post-link]
[/wpv-conditional]
</p>

Test the result in front-end, for example:
Closed post:
hidden link

Opening post:
hidden link

You can still edit it by clicking the link "Edit Projekt 02", after click the button "Uzavřít a odeslat", the post is closed, and the edit link won't display anymore

#1072551

Dear Luo Yang,

that's great, many thanks!

The only remained issue is now here: hidden link . It is a page where I had the post Form "Projekty" – and now there is a warning: "Form type and post type do not match".

Please explain me how to fix it.

Thanks again!!!

Jiri

#1072560

Dear Luo Yang,

finally, I got it!! ))

1. I had to clone Post Form "Projekty"

2. then I had to rename the Post Form "Projekty" to "Projekty - edit"

2. and in the settings of Post Form "Projekty" I had to change "Edit existing content" to "Add new content"

3. Then I was able to put Post Form "Projekty" into Layout "Projekty" and load it on "Soutěžní Projekt" Page to be visible on front-end.

Perfect, thanks again for your sophisticated help!

Best,

Jiri.