Skip Navigation

[Resolved] populate form fields

This support ticket is created 3 years, 2 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 8 replies, has 3 voices.

Last updated by Puntorosso 3 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1967537

I have a select field which I populate with custom posts

//dynamically populate Objekt select inquiry field with properties
add_filter( 'wpt_field_options', 'prefix_custom_options', 10, 3);
 function prefix_custom_options( $options, $title, $type ){
    switch( $title ){
        case 'all-objects-dropdown':
            $options = array(
            array(
      '#value' => '',
      '#title' => '',
	  	)
	  );
            $args = array(
                'post_type'        => 'objekt',
                'post_status'      => 'publish',
                'posts_per_page'   => -1,
                'orderby' => 'title',
				'order' => 'ASC'
      );
            $posts_array = get_posts( $args );
            foreach ($posts_array as $post) {
                $options[] = array(
                    '#value' => $post->ID,
                    '#title' => $post->post_title,
                );
            }
            break;
    }
    return $options;
}

Once the user select one entry I would like to pre-fill other fields of this form, extracting the corresponding values from the selected post.

Which is the best way?

#1968029

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

If I correctly understood your request, you want to populate another field when the user selects a value for the field "all-objects-dropdown", right?
You can add a generic field for that field without any values. Then, you will need to implement an AJAX call/action to return the possible values based on the selected item in "all-objects-dropdown". Read more about AJAX requests in WordPress in the following articles:
- https://developer.wordpress.org/plugins/javascript/ajax/
- hidden link

Please note that this is custom code, and is therefore out of the scope of the Toolset support forum. If you are not comfortable with programming consider hiring a developer. You may want to work with one of our partners https://toolset.com/contractors/

#1968639

I was checking the links you sent me, but couldn't help as they are too generic.
Any Toolset example on how to read/set Form fields through jscript?
Thanks for any suggestion.

#1968789

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I could not find any previous examples in our forum. But, I did find some of tutorials on how to implement an AJAX call in WordPress:
- hidden link
- hidden link
- hidden link

I have also found a couple of SO threads:
- https://stackoverflow.com/questions/51152414/wordpress-ajax-call-to-get-value-from-database-and-set-in-input-field-based-on-a
- https://stackoverflow.com/questions/49277808/populate-a-select-from-another-in-wordpress-and-cf7
- https://wordpress.stackexchange.com/questions/260773/how-do-i-use-ajax-to-build-a-dropdown-of-custom-fields-based-on-a-post-selected

And I found another example that is with Toolset, but it's not explained, you will have to read the code and understand what it does:
hidden link

#1969079

Thanks, I had already browsed those, as we are probably using the same search machine :))
They are too generic and related to direct sql queries.

Do you think Minesh could have some other idea? He already helped me in the past with Ajax/Javascript stuff.

By the way, I think the Toolset help miss some practical jscript snippets area, especially made for Toolset.

Coming from the Filemaker world, it's so frustrating to see that you need hours of coding, to achieve simple stuff you can solve with Filemaker in 10 seconds....

#1971945

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Puntorosso - Jamal passed this ticket to me.

Based on the information you shared and as per my understanding, it seems you want to implement the dependent dropdown feature. (like County -> State -> City) with Form you created using Toolset Form.

I'm afraid that there is no native feature available offered by Tooslet that you can use to display the dependent dropdowns like: Country -> State -> City.

By the way, I think the Toolset help miss some practical jscript snippets area, especially made for Toolset.
==>
I maybe agree on this but we have tons of features to be added to our product and it also depends on predefined priorities set by our Devs.

If you really like and want to see this feature should be added to our product, I strongly suggest you should file a new feature request using the following form that should be reviewed by our Product Manager:
- https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1972371

I understand your point.
But sometime, some small practical examples, like the usual County -> State -> City you mentioned, help us to achieve this "aahhh, now I got that" moment.

Once we have a direction it's just matter of trial-errors.
Without, it's just a walk in the dark.

Well, if there's no other option we can close the ticket.

Thanks

#1973131

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I'm afraid that there is no other option available at the moment but as said, I request you to file a new feature request:
- https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

There is no option/feature/workaround available at the moment. One possible workaround would be to add different generic select fields and add form's conditional statement. But again, it will be static values as you will require to add all select options manually. I'll try to find workaround in near future that should help users like you but I do not promise anything at the moment and there is no ETA on it.

#1974147

My issue is resolved now. Thank you!

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