Frontent Submission CPT logic
Support › MB Frontend Submission › Frontent Submission CPT logic
- This topic has 17 replies, 2 voices, and was last updated 2 years, 9 months ago by
Long Nguyen.
-
AuthorPosts
-
July 8, 2022 at 8:22 PM #36879
Marius Doko
ParticipantHello,
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!
July 9, 2022 at 4:09 PM #36893Long Nguyen
ModeratorHi 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.
July 9, 2022 at 6:44 PM #36895Marius Doko
ParticipantHello 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
July 10, 2022 at 6:00 PM #36902Long Nguyen
ModeratorHi,
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
valuepost.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.
July 10, 2022 at 6:09 PM #36904Marius Doko
ParticipantHey 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; }
July 11, 2022 at 1:01 PM #36905Long Nguyen
ModeratorHi,
You can change the value of argument
object_ids
to alocation
post ID and recheck this issue. For example:'object_ids' => 123,
July 11, 2022 at 2:46 PM #36906Marius Doko
ParticipantHello,
Thank you, that worked. But it's working for a single location. If I have multiple locations, what can be the best practice?
July 11, 2022 at 10:18 PM #36914Long Nguyen
ModeratorHi,
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 typelocation
above in real-time like working with JavaScript code.July 11, 2022 at 11:28 PM #36919Marius Doko
ParticipantI tried that but it's taking all the terms, THanks a lot Long!
July 12, 2022 at 10:28 PM #36950Long Nguyen
ModeratorHi,
On my demo site, the code works as well. Please check this screen record https://monosnap.com/file/rSsSyJXUFeFwrbxhfr4rnvhfxmX6Mr
July 13, 2022 at 1:10 AM #36955Marius Doko
ParticipantHello,
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
July 13, 2022 at 9:00 PM #36978Long Nguyen
ModeratorHi,
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
July 13, 2022 at 10:34 PM #36985Marius Doko
ParticipantHello 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.
July 14, 2022 at 1:44 AM #36988Marius Doko
ParticipantI 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/
July 14, 2022 at 9:05 PM #37009Long Nguyen
ModeratorHi,
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/
-
AuthorPosts
- You must be logged in to reply to this topic.