Skip Navigation

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

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

This topic contains 19 replies, has 2 voices.

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

Assisted by: Waqar.

Author
Posts
#1167862
Edit Post Form ‹ TRSA Buyers Guide — WordPress(1).png
Edit Post Form ‹ TRSA Buyers Guide — WordPress.png

I am trying to: update a current site and keep the same form working.

Link to a page where the issue can be seen:
hidden link
when you click the grey "Send to a Friend" button and try to use the drop down.

I expected to see: It should be working as it does on the site before the update:
hidden link

Instead, I got: After the update, dropdown doesn't work and links in email notification don't work.

#1168619

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Laura,

Thank you for contacting us and I'll be happy to assist.

I performed few tests and couldn't reproduce these issues on my test website.

For further troubleshooting, I'll suggest the following steps:

1. Please make sure all plugins are up-to-date.

2. Temporarily disable all the plugins, except the Toolset plugins and then check the form again.

3. Please also test the form with a default WordPress theme like Twenty Seventeen, to rule out any code conflict.

4. In case the issue still persists, I'll need access to the WordPress admin area, to see how the form, fields and the notification are configured.

I'm setting your next reply as private so that only you and our support team will have access to it.

Important note: Please make a complete backup copy of the website, before sharing the access details.

regards,
Waqar

#1168715

Thanks, Waqar. The theme and plugins are all the same as the live site. I am using this dev site to test the updates to core and Toolset.

#1168717

I am afraid to post login details here because the post doesn't seem to be private.

#1168735

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Laura,

Thanks for sharing the update and it is strange that your last message wasn't private.

Please share the login details in the next reply, which is also set to be private.
(I'll be observing the post, so you don't have to worry about it)

regards,
Waqar

#1169372

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Laura,

Thank you for sharing the login details and I was able to log in to the admin area successfully.

I'm going to perform a few tests on my website, based on the settings of your website and form.

Will follow up, as soon as I'll have an update.

Thank you for your patience.

regards,
Waqar

#1169698

Hi Waqar,
Is it possible that the way relationships are called in the forms has changed? This form is being called from an "Enhanced Listing" CPT but it is calling "Companies", which is a child. Companies are being shown elsewhere on the page, but thought that might have something to do with it. Also, it's being called from a custom PHP template: taxonomy-bg-category-garments-uniforms.php Thanks for your help on this!

#1169746

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Laura,

Thank you for waiting and for sharing the additional details.

I checked the form ("Send to a Friend Copy") connected to the "Send to a Friend" button and noticed that it was incorrectly using the company field:


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

I've updated it to use the correct shortcode and the company list is populating as expected now:


[cred_field field='@company_contact.parent' class='form-control' output='bootstrap' select_text='--- not set ---' ordering='desc' use_select2="never"]

You can view all the accepted parameters for the "cred_field" shortcode at:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

Similarly, to correctly show the parent company's information in the form notification, you'll find the following resources useful:
https://toolset.com/forums/topic/use-parent-post-name-into-cred-form-notification-title/
https://toolset.com/documentation/user-guides/how-to-use-custom-placeholders-in-cred-notifications/

I hope this helps.

regards,
Waqar

#1169963

Thanks so much for your help on this. I see that we are almost there. Now I just need to sort the company names by title. I tried several options of setting order="title", etc, but nothing seems to work. The documentation shows that this can't work with select2="never" but when I change it to always, the companies no longer show up. How can I sort by company name? Thanks so much!

#1170304

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Laura,

Thanks for sharing the update and glad you're making progress.

Your observation is correct and the way ordering parameter works, it can only be used, when the "select2" script is turned on for the dropdown's select field.

But, unfortunately, the way the popup/modal element is being used for displaying the form, it doesn't support the AJAX/script based "select2" drop-down selector.

If you'll remove the select2="never" attribute from the field's shortcode and insert the form directly into a test page's content (i.e. without a modal window), you'll see that it will work as expected.

An alternate can be to insert the form on your page directly (without the modal window) and show/hide it when the button is clicked, using some custom JavaScript.

regards,
Waqar

#1173520

Hi Waqar, I set up what you suggested here: hidden link on the "Send to a friend" button, but now I am not getting the companies to dropdown at all. I tried use_select2="always" and then removing it all together. This is the script I used in the PHP template:

<script>
		$(document).ready(function(){
    $("#formButton").click(function(){
        $("#form1").toggle();
    });
});
		</script>

and this is the code:

<li><button type="button" id="formButton">Send to a Friend</button>
			  <form id="form1">
			  <?php echo do_shortcode("[cred-form form='send-to-a-friend-copy']"); ?>
				</form>
			  </li>

Please let me know what I'm doing wrong. I need to get the companies to show in alphabetical order. Thanks so much for your help!

#1174151

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Laura,

The company select field works properly when the form is added into a page directly.
( e.g. hidden link )

This suggests that there is something wrong with the way the form is being included on the archive page, multiple times.
( hidden link )

One thing I noticed is that the IDs "formButton" & "form1" are repeating on the page, which makes their usage invalid.

A single page can only contain one unique instance of an ID.
( ref: hidden link )

You can convert the "formButton" & "form1" into classes in HTML and update your script accordingly.

If your goal is only to show an alphabetically ordered list of companies, as a drop-down field in a form, you can also follow a different approach:

1. For your "Contact Forms" post type, you can add a new custom field named "Company Name" and set it to be of type "select".

Note: you don't have to include all the options manually, as we'll generate them dynamically.

2. To generate the options, from the published posts in "Enhanced Listings" post type, you can add the following code, in your active theme's "functions.php" file:


add_filter( 'wpt_field_options', 'populate_select_for_companies', 10, 3);
function populate_select_for_companies( $options, $title, $type ){
	switch( $title ){
		case 'Company Name':
			$options = array();
			$args = array(
				'post_type' => 'enhanced-listing',
				'posts_per_page' => -1,
				'post_status' => 'publish',
				'orderby' => 'title',
				'order' => 'ASC'
			);

			$posts_array = get_posts( $args );
			foreach ($posts_array as $post) {
				$options[] = array(
					'#value' => $post->post_title,
					'#title' => $post->post_title,
				);
			}

		break;
	}
	return $options;
}

Note: Please make sure the title "Company Name" matches the title of the new custom field that was created.

I hope this helps and please let me know how it goes.

regards,
Waqar

#1174273

Hi Waqar,
Before I address any of the other stuff, the form does not work correctly on the test page:
hidden link

It is not alphabetical, and all the companies do not load. If you look at the red search box to the left of the form and notice the companies dropdown there - that is how the companies should look. There is a large number of companies and they are in alphabetical order. I'm trying to copy that drop down exactly. The drop down in the form in not like that.

Thanks for your assistance.

#1175138

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Laura,

Thanks for writing back and I apologize for missing out this detail earlier.

When a drop-down filter with "select2" script is used, it pre-populates only some options and shows the rest, based on what's typed in the field by the visitor.

To have a regular drop-down field with all options shown at once and in alphabetical order, the only option is to use a separate custom field and populate its options dynamically, as suggested in my last message.

Please let me know if any part of that approach is not clear and I'll explain it further.

regards & a Happy New Year,
Waqar

#1175203

Hi Waqar,
Thanks for your help so far, but I'm still not getting what I'd hoped for. As a reminder, let me review:

1) I have the live site that is has not been updated yet. It has the "Send to a Friend" form with a companies dropdown working exactly how I wanted it with the all the company names listed in alphabetical order. You will see that it is exactly the same as the read search box at the top left of the page. hidden link. All I'm trying to do is update Toolset on the dev site and have it work exactly the same way it worked before.

2) As instructed on the updated dev site, I have replaced the old code:

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

With the new code you gave me:

[cred_field field='@company_contact.parent' class='form-control' output='bootstrap' select_text='--- not set ---' ordering='desc' use_select2="never"]

It lists all the companies, like I wanted, but not in alphabetical order.

When I change the select2, I can't use the modal form. When I use the other hide/show option, only some companies show up and they are still not in alphabetical order.
When I use the custom field, as you suggested, as seen here: hidden link , companies show in alphabetical order, but not all companies are listed. And I need the notification email to send them the link to that company.

I'm thinking another possibility would be for the form to automatically know what company the enhanced listing is referring to and automatically send the link to that company without even having to do the dropdown? Can we do that?

I'm sorry to be going on like this but it's very frustrating when I was just trying to update the site and keep everything working like it was before. Thanks for your help!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.