Skip Navigation

[Resolved] Select current post by default on post form

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

Problem:
The user created two post forms for "For Sales" and "For Rent" and wanted guests to automatically select the current post they were viewing.

Solution:
The issue was resolved by setting a default value for the post element in the form. The user needed to add the [wpv-post-id] shortcode inside the default field of the post to have the item preselected.

cred form

To hide this preselected field from the visitors, CSS code was provided to make the select box invisible. The CSS selector is specific to the ID of the form. Here’s an example of the CSS code:

#cred_form_573_1_1 > .form-group:first-child {
  display: none;
}

In this code, "573" is the ID of the form. The user can adapt this code for other forms by changing the form ID accordingly.

Relevant Documentation:

https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-when-a-parent-post-is-preselected

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 8 replies, has 2 voices.

Last updated by Christopher Amirian 1 year, 3 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2638389
2023-08-29.jpg
2023-08-29 (1).jpg

Tell us what you are trying to do?

I've created 2 post forms "Quan tâm tin bán" (Interested in Sales) and "Quan tâm tin thuê" (Interested in Rents) for "Tin bán" (For Sales) and "Tin thuê" (For Rent). In the post forms, a guest must choose the post they want. So, are there any ways to select the current post that the guest is on?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2638507

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

As the form is using advanced Select2 library to select the post it is not possible to give jQuery code to pre-select the post.

I wonder how you set the form and if it is possible to use a simpler normal HTML select so that I might be able to give you a code to pre-select the post.

Thanks.

#2638515

Excuse me. I'm not ITer so I don't understand things you're saying. I remember that in the past, someone in Toolset team helped me fix the post form select the current post by default and hide this process in front end. He solved it directly, I didn't understand what he did. I lost that website and am creating again. I know a little about HTML, CSS. Please guide me.

#2639357

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I will be happy to help but I need to know the setup you use.

I'd appreciate it if you could give me the URL/User/Pass of your WordPress dashboard after you make sure that you have a backup of your website.
It is absolutely important that you give us a guarantee that you have a backup so if something happens you will have a point of restore.

Make sure you set the next reply as private.

Please give me the information below:

- What is the link to the Form Edit screen?
- Where did you use the Form? Content Template, Widget, ...

Thanks.

#2640467

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I see the issue, usually when it comes to the default item selection, you should link to the form using a button that adds the proper URL parameter to do the default selection using the method below:

https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-when-a-parent-post-is-preselected

But for your use-case you directly added the form inside the single post template.

I asked the second tier support about this to see if there can be a solution for that.

Thanks.

#2641453

Hi Christopher,

Is there any news for my issue?

Best regards.

#2641687

Christopher Amirian
Supporter

Languages: English (English )

Screenshot 2023-09-07 at 13.30.19.png

Hi there,

I have an answer from the second tier support.

You basically need a default value set for the post element in the form.

The post element has a field in the form edit screen to have the default item and Toolset has a shortcode that shows the current post ID called: [wpv-post-id]

By adding that shortcode inside the default field of the post you will have the item preselected.

I did it for the Tin Ban form and you can do the same for the other forms. Please check the screenshot.

Thanks.

#2641871

Hi Christopher,

I got it. Thank you so much.

By the way, could you please guide me to hide this preselected field? I mean a visitor won't be allowed to know and change it.

Maybe this is the last thing regarding to this issue.

Best regards.

#2642487

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

As the select box in question is the first item of the form, it is possible to use the CSS code below to hide it:

#cred_form_573_1_1 > .form-group:first-child {
  display: none;
}

I added that to the CSS Editor of the form.

In the CSS code above, 573 is the ID of the form, so you can use the same method for the other forms. For example, another form with the ID of 222 will have the CSS code below:

#cred_form_222_1_1 > .form-group:first-child {
  display: none;
}

Thanks.

#2643109

Thank you very much.