Skip Navigation

[Resolved] Toolset form submission

This support ticket is created 4 years, 8 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 5 replies, has 2 voices.

Last updated by Minesh 4 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1870633

I have a form set up to add new members to a Post type, within the post type I have set categories with the year of the membership eg 2020. When a user fills out the form I want them to automatically get added to this category. This element can be hidden on the form.

#1871851

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Toolset Forms offers API hook cred_save_data that you should use to set default taxonomy term for the post you created using the form.

For example - You can add the following code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_action('cred_save_data', 'func_set_default_terms',10,2);
function func_set_default_terms($post_id, $form_data) {
  $forms = array( 99999 );
  if ( in_array( $form_data['id'], $forms ) ) {
    
    wp_set_object_terms($post_id, 'term-slug', 'taxonomy-slug', true);
  }
}

Where:
- Replace 99999 with your original form ID.
- Replace term-slug and taxonomy-slug as required

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
=> https://codex.wordpress.org/Function_Reference/wp_set_object_terms

#1879067

Hi

Not sure I understand your code

My form is on the following page

hidden link

The form id is 861, the first element on the form is Membership Years, I would like the box named 2021-2022 to be automatically checked so when someone submits the form their membership is allocated to the correct year.

Membership Years is a taxonomy and the slug is membership-year
2021-2022 and 2021-2022 are categories, 2021-2022 has ID=52

Can I do this with js code, not sure the below code is correct but hope you could help or advise or how do I adapt your code and where do I need to put this.

jQuery(document).ready(function($) {
jQuery("select[name^='membership-year'] option[value='2021-2022']").attr("selected","selected");
});

#1879121

Minesh
Supporter

Languages: English (English )

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

If you are going to preselect the taxonomy then the code I shared is not required.

If you want to use JS to select the taxonomy term checkbox by default, could you please try to use the following JS code and add it to your form's JS box:

jQuery(document).ready(function() {
  
jQuery(':checkbox[value=51]').prop('checked', true);
    
});

Can you please try above JS code and see when your form is loaded you see the checkbox checked automatically.

#1879217
Screenshot 2020-12-17 at 12.29.04.png

That worked fine, thank you.

I also want to filter the following page.
hidden link

In the blue box I have a view which contains the membership years. I have put the same code in the js but can't get the default date to be checked. Do I need the code somewhere else.

#1879259

Minesh
Supporter

Languages: English (English )

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

Glad to know that solution I shared help you to resolve your issue.

That is totally new issue. As per our support policy, we entertain only one question per ticket. This helps other users searching on the forum as well as help us to write correct problem resolution summery for the original issue reported and fixed with this ticket.

May I kindly ask you to open a new ticket with every new question you may have. You are welcome to mark resolve this ticket.

Thank you for understanding.