Skip Navigation

[Resolved] Dropdown not working in form (and link not working in email notification)

This support ticket is created 5 years, 11 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/Karachi (GMT+05:00)

This topic contains 19 replies, has 2 voices.

Last updated by lauraH-2 5 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#1175408

Hi Laura,

Thank you for sharing the summary again.

Your newly suggested approach of dropping the company selection field seems to be a good idea, as visitors will be clicking the sharing button from a specific company, already.

There will be a couple of steps involved, but the end result would be more efficient, both in terms of user experience and page loading.

1. You can add the following code to register two new shortcodes in your active theme's "functions.php" file, which will get the company's post ID from the URL and will return the name and the URL for the form:


add_shortcode( 'show-company-info-name', 'show_company_info_name_func');
function show_company_info_name_func($atts){
	
	if( (isset($_GET['company-id'])) && (!empty( $_GET['company-id'])) ) {
		$company_id = $_GET['company-id'];

		$name = esc_html( get_the_title($company_id) );

		if( !empty($name) ) {
			return $name;
		}
	}
}

add_shortcode( 'show-company-info-url', 'show_company_info_url_func');
function show_company_info_url_func($atts){
	
	if( (isset($_GET['company-id'])) && (!empty( $_GET['company-id'])) ) {
		$company_id = $_GET['company-id'];

		$URL = get_permalink($company_id);

		if( !empty($URL) ) {
			return $URL;
		}
	}
}

2. In your form, you can replace the existing company select field with the following generic field:


<div class="form-group">
	<label>Company Information</label>
	[cred_generic_field type='textarea' field='company info']
	{
	"required":0,
	"default":"[show-company-info-name] - ( [show-company-info-url] )"
	}
	[/cred_generic_field]
</div>

3. Instead of loading the form multiple times on your archive page ( e.g. hidden link ), you can create a special dedicated page with the form ( similar to the one at hidden link )

Note: You can hide the extra page elements like header, footer and sidebar from that new form page, using custom CSS code.

4. When you'll pass on the company's ID through the URL parameter "company-id", the form will automatically show the name and the URL in that newly added field.

e.g. hidden link

In your archive page's loop, you can dynamically replace "123" with the current company's ID and set that new page to open in a new tab or popup, when its "Send to a friend link is clicked".

I hope this helps! Please let me know how it goes and if you need any further assistance around this.

regards,
Waqar

#1175453

Thanks for this Waqar, but it seems like there should be a an easier way, so I can keep the modal form. When I add [wpv-post-title] to the form, it is showing the correct company, but when I try putting it in the notification, the link is not working. I also read this article, where the parent can be preselected and hidden: https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/
Is there a way to do that with this form?

#1175780

Hi Laura,

As you noted, the "[wpv-post-title]" shortcode only returns the title but not the link.
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153369 )

If you'd like to get the title as a link, you can use "[wpv-post-link]".
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153370 )

To get only the post's URL, you can use "[wpv-post-url]".
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-154469 )

Note: the guide that you mentioned, is applicable for a case where parent/child relationship already exists between the two posts.

regards,
Waqar

#1176037

Hi Waqar,
Yes, I know these shortcodes. The problem is that the info shows in the form, but not the notification email. How can I add the [wpv-post-link] to the email notification? If I can just do that, then I would be all set. Thanks!

#1176072

After going through all this about not being able to use the modal form and needing to put the form on another page, adding stuff to the functions file, etc, I found a very simple solution. All I needed to do was to change was to add the use_select2.

[cred_field field="_wpcf_belongs_company_id" value="" order="date" ordering="desc" no_parent_text="No Parent"]

to

[cred_field field="_wpcf_belongs_company_id" value="" order="title" ordering="asc" no_parent_text="No Parent" use_select2="never"]

I was able to keep everything else exactly the same. It now works perfectly and I kept the modal form.