Support Forum
Hi.
I wonder if I could get some direction on this scenario.
I have a form which I'm displaying using the shortcode [mb_frontend_form id='job-details'].
The form is created in Builder with:
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => esc_html__( 'Job Details', 'text-domain' ),
'id' => 'job-details',
'post_types' => ['page'],
'context' => 'normal',
'priority' => 'high',
'fields' => [
[
'id' => $prefix . 'JobID',
'type' => 'number',
'name' => esc_html__( 'Job ID', 'text-domain' ),
'tab' => 'tab_job',
],
[
'id' => $prefix . 'ClientID',
'type' => 'number',
'name' => esc_html__( 'Client ID', 'text-domain' ),
'tab' => 'tab_job',
],
[
'id' => $prefix . 'Start_Date',
'type' => 'date',
'name' => esc_html__( 'Start Date', 'text-domain' ),
'tab' => 'tab_job',
],
[
'id' => $prefix . 'End_Date',
'type' => 'date',
'name' => esc_html__( 'End Date', 'text-domain' ),
'tab' => 'tab_job',
],
[
'id' => $prefix . 'g_Sitters',
'type' => 'group',
'fields' => [
[
'id' => $prefix . 'SitterID',
'type' => 'number',
'name' => esc_html__( 'Sitter ID', 'text-domain' ),
],
[
'id' => $prefix . 'Sitter_Start_Date',
'type' => 'date',
'name' => esc_html__( 'Start Date', 'text-domain' ),
],
[
'id' => $prefix . 'Sitter_End_Date',
'type' => 'date',
'name' => esc_html__( 'End Date', 'text-domain' ),
],
],
'clone' => 1,
'default_state' => 'expanded',
'max_clone' => 5,
'add_button' => esc_html__( 'Add additional sitter cover', 'text-domain' ),
'tab' => 'tab_sitters',
],
],
'tab_style' => 'default',
'tab_wrapper' => true,
'table' => 's4p_job',
'tabs' => [
'tab_job' => [
'label' => 'Job Details',
'icon' => 'dashicons-calendar',
],
'tab_sitters' => [
'label' => 'Assigned Sitters',
'icon' => 'dashicons-businessman',
],
],
'include' => [
'relation' => 'OR',
'user_role' => ['administrator'],
],
'storage_type' => 'custom_table',
];
return $meta_boxes;
}
As you can see I'm saving the data in a custom table with the code below and this works fine.
add_action( 'init', 'prefix_create_table' );
function prefix_create_table() {
if ( ! class_exists( 'MB_Custom_Table_API' ) ) {
return;
}
MB_Custom_Table_API::create( 's4p_job', array(
'JobID' => 'INT NOT NULL',
'ClientID' => 'INT NOT NULL',
'g_Sitters' => 'VARCHAR(65535) NOT NULL',
'Start_Date' => 'DATE NOT NULL',
'End_Date' => 'DATE NOT NULL',
) );
}
What I'd like to be able to do is have the form populate with the data from the custom table based on a search.
My search would be a simple list of all the rows in the table for now (SELECT *...) but I'll later need to modify on other custom fields as well.
Once I have the ID I'd then need my frontend form to be populated with the values from this table and any changes to the values made in the form be updated back to that row.
I'd also like similar behaviour with user meta which I have working with my custom fields all saved against the logged in user in the standard table but would be better if I could save this date in a custom table too and have it connected to the form properly from there as well.
Any help would be much appreciated.
Thanks.