Support Forum
Support › MB Frontend Submission › Front end form can save on custom database?Resolved
hi
I was wondering if its possible to save data from front end submission to a custom existing database. many thanks
Hi,
Yes, it's possible to save the data from Frontend Submission to a custom table in the same database. But please note that the field ID must match with the column key of the custom table.
For more information, please follow the documentation:
https://docs.metabox.io/extensions/mb-custom-table/#notes
https://docs.metabox.io/extensions/mb-custom-table/#using-existing-tables
Hi Long, thanks for your help. will give it a try
Hi Long, not sure why frontend submission is not working for me, code below, can you help please ? Doesn´t save on the database nor give confirmation message ....thanks
shortcode [mb_frontend_form id='cliente' confirmation]
metabox code
<?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__( 'Cliente', 'text-domain' ),
'id' => 'cliente',
'post_types' => ['budget'],
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
'fields' => [
[
'id' => $prefix . 'post_title',
'type' => 'text',
'name' => esc_html__( 'title', 'text-domain' ),
'class' => 'post_title',
],
[
'id' => $prefix . 'numero_proposta',
'type' => 'text',
'name' => "###N\xc3\x9aMERO PROPOSTA###",
'class' => 'numero_proposta',
],
[
'id' => $prefix . 'nome_cliente',
'type' => 'text',
'name' => esc_html__( 'NOME', 'text-domain' ),
'class' => 'nome_cliente',
],
],
'table' => 'bdg_tanksbr',
'storage_type' => 'custom_table',
];
return $meta_boxes;
}
post_type code
function your_prefix_register_post_type() {
$args = array (
'label' => esc_html__( 'budgets', 'text-domain' ),
'labels' => array(
'menu_name' => esc_html__( 'budgets', 'text-domain' ),
'name_admin_bar' => esc_html__( 'budget', 'text-domain' ),
'add_new' => esc_html__( 'Add new', 'text-domain' ),
'add_new_item' => esc_html__( 'Add new budget', 'text-domain' ),
'new_item' => esc_html__( 'New budget', 'text-domain' ),
'edit_item' => esc_html__( 'Edit budget', 'text-domain' ),
'view_item' => esc_html__( 'View budget', 'text-domain' ),
'update_item' => esc_html__( 'Update budget', 'text-domain' ),
'all_items' => esc_html__( 'All budgets', 'text-domain' ),
'search_items' => esc_html__( 'Search budgets', 'text-domain' ),
'parent_item_colon' => esc_html__( 'Parent budget', 'text-domain' ),
'not_found' => esc_html__( 'No budgets found', 'text-domain' ),
'not_found_in_trash' => esc_html__( 'No budgets found in Trash', 'text-domain' ),
'name' => esc_html__( 'budgets', 'text-domain' ),
'singular_name' => esc_html__( 'budget', 'text-domain' ),
),
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'show_in_rest' => true,
'menu_position' => 2,
'menu_icon' => 'dashicons-carrot',
'capability_type' => 'page',
'hierarchical' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite_no_front' => false,
'supports' => array(
'revisions',
),
'rewrite' => true,
);
register_post_type( 'budget', $args );
}
add_action( 'init', 'your_prefix_register_post_type' );
Hi,
You can add the attribute post_type
to the shortcode to define the post type to save data.
[mb_frontend_form id="cliente" post_fields="title,content" post_type="budget"]
Read more in the documentation https://docs.metabox.io/extensions/mb-frontend-submission/#shortcode-attributes.
Thanks Long, I will try on a fresh wordpress installation... tried already what you told me but didn't work. cheers