Support Forum
Support › MB Frontend Submission › Frontent Submission CPT logic
Hello,
I am trying to create a frontend form where the user can select the location (cpt) and based on that he can select all the related Agents. I tried to add a Post Field with CPT Location and Taxonomy Agent, but when i select a location, it displays to select all the agents instead.
Tried to add conditional logic or query args but so far no luck.
Can I get help on how to display something like that, please?
Thank you a lot!
Hi Marius,
You can use the setting query_args
to limit posts by some arguments (like tax_query), please read more on this documentation https://docs.metabox.io/fields/post/
But the field does not support changing the argument value based on another field value immediately like using JS code, just on loaded.
Hello Long,
For Taxonomies - Agents, i set the query_args to taxonomy: profile hide_empty: false, objet_ids: post.ID
But i couldn't get the related Agents from that Field location that i select. Am i missing any step or is it wrong?
The second question(more like informative): Is it possible to create a custom form in View, using the fields from Custom Fields? Or is it a must to have the frontend shortcode from the custom field? I could give that way also a try and see how it goes
Hi,
Can you please share the code that creates the field group used with the extension MB Frontend Submission? Please note that this code used PHP code to register the field group, it does not work like the View with Twig code so the argument object_ids
value post.ID
won't work in this case.
For the second question, the view works like a template to output the field value. It is possible to create a custom form with View but not possible to add the fields from the Insert Field tab.
Hey Long,
Here is my code, I did some tests and this is how it is atm. I tried to create a connection through these query args between Location CPT and Profile taxonomy, but so far I couldn't achieve it
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Appointment Fields', 'your-text-domain' ),
'id' => 'appointment-fields',
'post_types' => ['appointments'],
'fields' => [
[
'name' => __( 'Email', 'your-text-domain' ),
'id' => $prefix . 'appointment_email',
'type' => 'email',
'required' => true,
],
[
'name' => __( 'Location', 'your-text-domain' ),
'id' => $prefix . 'appointment_location',
'type' => 'post',
'post_type' => ['location'],
'field_type' => 'select_advanced',
],
[
'name' => __( 'Appointment Profile', 'your-text-domain' ),
'id' => $prefix . 'appointment_profile',
'type' => 'taxonomy',
'taxonomy' => ['profile'],
'field_type' => 'select_advanced',
'query_args' => [
'hide_empty' => false,
'object_ids' => 'post.ID',
],
],
[
'name' => __( 'Date', 'your-text-domain' ),
'id' => $prefix . 'date_c2mghcmnqoq',
'type' => 'date',
],
],
];
return $meta_boxes;
}
Hi,
You can change the value of argument object_ids
to a location
post ID and recheck this issue. For example:
'object_ids' => 123,
Hello,
Thank you, that worked. But it's working for a single location. If I have multiple locations, what can be the best practice?
Hi,
For multiple locations, you can use an array of IDs
'object_ids' => [123, 456, 789]
But it does not support getting the location IDs from the field post
with post type location
above in real-time like working with JavaScript code.
I tried that but it's taking all the terms, THanks a lot Long!
Hi,
On my demo site, the code works as well. Please check this screen record https://monosnap.com/file/rSsSyJXUFeFwrbxhfr4rnvhfxmX6Mr
Hello,
Yes, that way I tried and it works, but what I was trying to make was:
Once you click the specific location taxonomy, it will show only the related Profiles to that taxonomy for choosing. In case you have 4 location terms and you define all ids of locations, will not display the related profiles but will display all these profiles in 4 location terms instead.
But I found a solution for it, I created this form using select advanced + conditional logic. So no need to use the logic from taxonomies.
I have a couple of more questions if that's fine.
- I am trying to disable Saturdays and Sundays for Datepicker, but it doesn't work the way that I am adding it. I tried also doing it as [0,6]. https://tinyurl.com/23xosb8k
- Is it possible to set up an email for the form submission? Like when someone fills the form, goes email from our site to that person
Hi,
1. It looks like daysOfWeekDisabled
is an attribute of the Bootstrap jQuery library, not an attribute of the DatePicker Widget of jQuery library that Meta Box used.
https://getdatepicker.com/4/Options/#daysofweekdisabled
https://api.jqueryui.com/datepicker/
Please read more on the documentation https://docs.metabox.io/fields/date/
2. Yes, it is possible. Please follow this documentation to use a form hook to send an email to the user after submitting the form https://docs.metabox.io/extensions/mb-frontend-submission/#form-hooks
Hello Long, for the 1st question, i am using this code to disable weekends as per their instructions, I added it in the View Javascript area, also i tested it from the file folders by creating a js file, but didn't work either. Do you have any solution for how you would achieve this?
<script type="text/javascript">
$(function () {
$("#exampleDatepicker4").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
beforeShowDay: $.datepicker.noWeekends
});
});
</script>
I saw the documentation which you sent me by links, and there was only how to display the field date which i have it already.
For the 2nd question, I tried it but it didn't work, probably because i am using it on local website, but the link redirection worked.
I am using the custom fields in MB View through Frontend Submission Shortcode, I tried many ways and couldn't make it work. I followed also this guide from this link https://codehasbug.com/javascript/disable-specific-date-in-jquery-datepicker/
Hi,
Please understand that the view template is only rendered in the frontend so the jQuery library might not work in your case. Please follow this documentation to know how to enqueue the script file and implement the code again https://developer.wordpress.org/reference/functions/wp_enqueue_script/