Skip Navigation

[Resolved] Post Form and Post Content at the same page/link?

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

Problem: On one page of my site, I would like to display a Form that allows Users to create a post. If the User has already created a post, the Form should not be displayed. Instead, the post should be displayed.

Solution: Use conditional HTML to show or hide the Form.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 3 voices.

Last updated by Christian Cox 6 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1072573

Hello,

I already have the Post Form placed at some page with a possibility of editing the Post Form content.
Because THE POST FORM IS GOING TO BE USED FOR ONE CONTENT/SUBMISSION ONLY then I would like to have the Post Form and the Post Content at the same page/link.

My explanation:

1. If the user is coming to visit the page/link for the first time - there is a Post Form where the user can submit a content.

2. If the user already submitted the content with using that Post Form then there (on the same page) is no Post Form visible again but only the content. And there the user can also edit this content.

So it means that everything is "happening" in the same place/page/link.

How to make it with Toolset? Many thanks for your help!

Best,

Jiri.

P. S. Previously I was creating this Post Form with the brilliant help of Mr. Luo Yang here: https://toolset.com/forums/topic/possibility-of-save-and-also-send-and-close-button-in-content-form/

#1073401

For this to work you need your User (visitor) to be logged in on your site.

Once that is granted (the visitor is hence a registered WordPress user), you can do this with HTML conditionals and some Custom Code.

I have elaborated in past how to show a certain Form only one time ever, and others have. This is still working the same.
Solutions can be:
https://toolset.com/forums/topic/cred-before-save-data-allow-only-one-submition-of-the-form/

That acts on the form directly.
Now, another solution can be:

1. Create a Custom ShortCode that counts how many posts of a type a certain user already created:

/**
 *Count posts of given type, so each user can create post only once
 */
function u_post_count() {
    $user_post_count = count( get_posts( array( 
    'post_type' => 'your_post_type', 
    'author'    => get_current_user_id(), 
) ) );
        
    return $user_post_count;
}

2. Use a Conditional HTML to show the Create New Post Form only if the above count is less than one.
This can be done after you register the above ShortCode in your functions.php file, and then in Toolset > Settings > Front End Content > 3rd party ShortCodes
After, you can use it in a HTML conditional:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

3. Use a HTML conditional to hide the edit form as long the post count is less than one and show it if the count is 1.

That will allow you to show everything on once single page.

#1073545

Hello Beda,

many thanks for your help and suggestion!!!

My questions:

1. I've already put this code to my theme's functions.php file:

/**
*Count posts of given type, so each user can create post only once
*/
function u_post_count() {
$user_post_count = count( get_posts( array(
'post_type' => 'your_post_type',
'author' => get_current_user_id(),
) ) );

return $user_post_count;
}

I just don't know if there is a need to edit anything inside this code or not. For example: does 'your_post_type' can stay like this or do I have to change it for my use?

2. I've already made [projekty_submit] shortcode here: hidden link

3. I'm trying to create conditional logic in my 2 forms: Projekty (ID: 219) and Projekty - edit (ID: 166)

As you suggested I'm trying to edit Projekty (ID: 219) Post Form and putting the conditional function at the beginning of the Post Form code (please look here hidden link

I just don't know how to write if this in the Projekty (ID: 219) Post Form:

[wpv-conditional if="( '[projekty_submit]' eq '1' )"] then SHOW this form

and

in the code of Projekty - edit (ID: 166) Post Form:

[wpv-conditional if="( '[projekty_submit]' eq '<-1' )"] then HIDE this form.

Thank for your further help,

best!

Jiri

#1074368

For example: does 'your_post_type' can stay like this or do I have to change it for my use?
You must replace your_post_type with the slug of your post type.

I just don't know how to write if this in the Projekty (ID: 219) Post Form:
You must move the conditional outside the Form contents. Wrap the conditional around the Form shortcode in your View, like this:

[wpv-conditional if="( '[projekty_submit]' eq '1' )"] 
[cred_form form="your-form-slug"]
[/wpv-conditional]

Replace your-form-slug with the slug of your Form.

Or hide it like this:

[wpv-conditional if="( '[projekty_submit]' eq '1' )" evaluate="false"] 
Do not display the form.
[/wpv-conditional]
#1074369

Dear Christian,

many thanks for your help!

"You must replace your_post_type with the slug of your post type." – OK, thanks for your explanation!

"You must move the conditional outside the Form contents. Wrap the conditional around the Form shortcode in your View....." – OK, but maybe I'm a little bit lost here...

I thought that I should put the code at the Post Form (that's not true as you wrote already) or at the Layout/Template to have finally both the Form and the Post content on the form at the same page/link as I already mentioned:

"1. If the user is coming to visit the page/link for the first time - there is a Post Form where the user can submit a content.

2. If the user already submitted the content with using that Post Form then there (on the same page) is no Post Form visible again but only the content. And there the user can also edit this content.

Because THE POST FORM IS GOING TO BE USED FOR ONE CONTENT/SUBMISSION ONLY then I would like to have the Post Form and the Post Content at the same page/link."

In fact, I understood that the View is a list of Post contents and I don't know how to make possible to have both the Post Form (Post Form or Post-edit Form) and the Post Content at the same page/link WHEN I have to use Toolset View and place this code into View's content as you recommended:

"[wpv-conditional if="( '[projekty_submit]' eq '1' )"]
[cred_form form="your-form-slug"]
[/wpv-conditional]
Replace your-form-slug with the slug of your Form.

Or hide it like this:

[wpv-conditional if="( '[projekty_submit]' eq '1' )" evaluate="false"]
Do not display the form.
[/wpv-conditional]"

I was planning to use View of Post Contents only for my use as the administrator – to see the list of users' forms results which is not going to be visible to ordinary users/subscribers.

But maybe I still don't understand "the goal" of your recommendation – then I'm sorry for my misinterpretation.

Many thanks for your another explanation.

Best,

Jiri.

#1074860

Hello,

to be more specific:

Here I have my Post Form: hidden link

Here is a screenshot of a Content Page after submitting the Post Form: hidden link That is working fine already.

What I need is to have this page/content at the same link as the Post Form because every user is able to submit ONE content only so there is no need to divide the Post Form and the View of Contents to different pages/links.

It means that after submitting a form by a user and going again at the same link I need to see this: hidden link

But I see this: hidden link

Many thanks for any help and suggestion.

Best,

Jiri

#1074990

I misunderstood, sorry. Disregard what I said about the View. Instead, use conditionals in your Content Template or Layout for this post. If the shortcode returns 0, you know the User has not created a post yet.

Just after that conditional, insert the second conditional. Use evaluate="false" this time, which tests if the shortcode does not return 0. If the shortcode does not return 0, you know the User has created a post already and should see the post content.

[wpv-conditional if="( '[projekty_submit]' eq '0' )"] 
[cred_form form="your-form-slug"]
[/wpv-conditional]

[wpv-conditional if="( '[projekty_submit]' eq '0' )" evaluate="false"] 
Show the post content here
[/wpv-conditional]
#1075041

Dear Christian,

thanks for your patience and help!

Unfortunately, your suggestion still doesn't work.

Probably I'm doing something wrong:
About the code:

1. Now I know where to put it – into my Layout. Fine, thanks!

2. About this part of the code: [cred_form form="your-form-slug"]
My Post form slug is "projekt". So in the functions.php I put the code:

/**
*Count posts of given type, so each user can create post only once
*/
function u_post_count() {
$user_post_count = count( get_posts( array(
'post_type' => 'projekt',
'author' => get_current_user_id(),
) ) );

return $user_post_count;
}

My Post Form name is "Projekty" but I CAN'T SEE ANY SLUG in the Post Form's settings. So is the slug "projekt" or "projekty"? What to put here: [cred_form form="your-form-slug"] ?

3. About the submit field:

In Post Form "Projekty" I have this submit field:

[cred_field field='form_submit' value='Odeslat' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

and In the "Projekty-edit" I have these two submit fields:

[cred_field field='form_submit' value='Uložit' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[cred_field field='form_submit' value='Uzavřít a odeslat přihlášku' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

One button is for Saving and the other for Closing of editing. I made this function with the help of Mr. Luo Yang as it is described here: https://toolset.com/forums/topic/possibility-of-save-and-also-send-and-close-button-in-content-form/

So may use "form_submit" or "projekty_submit" inside this code?

[wpv-conditional if="( '[projekty_submit]' eq '0' )"]
[cred_form form="your-form-slug"]
[/wpv-conditional]

[wpv-conditional if="( '[projekty_submit]' eq '0' )" evaluate="false"]
Show the post content here
[/wpv-conditional]

Sorry and many thanks again!

Best,

Jiri.

#1076345
Screen Shot 2018-08-07 at 10.08.18 AM.png

My Post Form name is "Projekty" but I CAN'T SEE ANY SLUG in the Post Form's settings. So is the slug "projekt" or "projekty"?
Instead of trying to guess the Form slug or write the cred_form shortcode manually, use the Toolset Forms button to insert the shortcode automatically. See the screenshot.

So may use "form_submit" or "projekty_submit" inside this code?
The submit buttons should be placed inside the Form editor. Do not include the button shortcodes in this conditional code. Only insert the cred_form shortcode inside the conditional code. The cred_form shortcode contains the entire Form, including the buttons:

[cred_form form="your-form-slug"]

If the button shortcodes are placed inside the Form editor, they will appear when the cred_form shortcode renders the Form.