Support Forum
Support › MB Frontend Submission › Group Fields Data not showing
Hi why the ws_getprice_container_type_group fields is not showing under a group field.
// getprice form after submission
add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
if ( 'get-price' === $config['id'] ) {
$ws_getprice_from = empty( $_POST['ws_getprice_from'] ) ? null : $_POST['ws_getprice_from'];
$ws_getprice_to = empty( $_POST['ws_getprice_to'] ) ? null : $_POST['ws_getprice_to'];
$ws_getprice_container_type_group = empty( $group = $_POST['ws_getprice_container_type_group'] ) ? null : $_POST['ws_getprice_container_type_group'];
$ws_getprice_container_type_select = $group['ws_getprice_container_type_select'];
$to = '[email protected]';
$subject = 'New Inquiry';
$body = '<div class="mail-body" style="color:#ccc;">Your application details: ' . '' . '<div>' . 'From:' . $ws_getprice_from . '</div>' . '<div>' . 'To:' . $ws_getprice_to . '</div>' . 'Container Type:' . $ws_getprice_container_type_select . '</div>';
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
wp_mail( $to, $subject, $body, $headers );
wp_safe_redirect( 'thank-you' );
die;
}
}, 10, 2 );
Hi Kirb,
Can you please share the code that creates custom fields on your site? I will help you to check the issue.
Hi, Long. Here it is. Can you help me display all the custom fields in the email? Including the group and its items. Thanks in advanced.
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Get Price', 'your-text-domain' ),
'id' => 'get-price',
'post_types' => ['page', 'post'],
'style' => 'seamless',
'class' => 'getprice-form',
'fields' => [
[
'type' => 'heading',
'name' => __( 'Route', 'your-text-domain' ),
],
[
'name' => __( 'From', 'your-text-domain' ),
'id' => $prefix . 'ws_getprice_from',
'type' => 'select_advanced',
'options' => [
'alesund' => __( 'Ålesund (Norway)', 'your-text-domain' ),
'averoy' => __( 'Averøy (Norway)', 'your-text-domain' ),
'bremerhaven' => __( 'Bremerhaven (Germany)', 'your-text-domain' ),
],
'placeholder' => __( 'Port & Place', 'your-text-domain' ),
'required' => true,
'columns' => 5,
'class' => 'ws-getprice-from',
],
[
'id' => $prefix . 'custom_html_sann48gtpha',
'type' => 'custom_html',
'std' => '<button type="button" class="from-to__flip" tabindex="-1" aria-label="Flip from and to"><svg width="25px" height="20px" viewBox="0 0 25 20" class="icon icon--flip"><g><line class="icon__line" x1="14.2" y1="6.5" x2="2.2" y2="6.5"></line><polyline class="icon__line" points="6.5,12 1,6.5 6.5,1"></polyline><line class="icon__line" x1="10.6" y1="13.5" x2="22.6" y2="13.5"></line><polyline class="icon__line" points="18.4,8 23.9,13.5 18.4,19"></polyline></g></svg></button>',
'columns' => 2,
],
[
'name' => __( 'To', 'your-text-domain' ),
'id' => $prefix . 'ws_getprice_to',
'type' => 'select_advanced',
'options' => [
'alesund' => __( 'Ålesund (Norway)', 'your-text-domain' ),
'averoy' => __( 'Averøy (Norway)', 'your-text-domain' ),
'bremerhaven' => __( 'Bremerhaven (Germany)', 'your-text-domain' ),
],
'placeholder' => __( 'Port & Place', 'your-text-domain' ),
'required' => true,
'columns' => 5,
'class' => 'ws-getprice-to',
],
[
'name' => __( 'Containers', 'your-text-domain' ),
'id' => $prefix . 'ws_getprice_container_type_group',
'type' => 'group',
'clone' => true,
'add_button' => __( 'Add container type', 'your-text-domain' ),
'fields' => [
[
'name' => __( 'Container Type', 'your-text-domain' ),
'id' => $prefix . 'ws_getprice_container_type_select',
'type' => 'select_advanced',
'options' => [
45 => __( '45\' dry container', 'your-text-domain' ),
40 => __( '40\' dry container', 'your-text-domain' ),
20 => __( '20\' dry container', 'your-text-domain' ),
'45-reefer' => __( '45\' reefer (refrigiated)', 'your-text-domain' ),
'20-feet-flat-rack' => __( '20\' flat rack', 'your-text-domain' ),
'40-feet-flat-rack' => __( '40\' flat rack', 'your-text-domain' ),
'40-feet-flat-rack-high' => __( '40\' flat rack high cube', 'your-text-domain' ),
],
'placeholder' => __( 'Select container type', 'your-text-domain' ),
'columns' => 8,
'class' => 'ws-getprice-container-group',
],
[
'name' => __( 'Number', 'your-text-domain' ),
'id' => $prefix . 'ws_getprice_quantity',
'type' => 'number',
'columns' => 4,
'class' => 'ws-getprice-quantity',
],
[
'id' => $prefix . 'ws_getprice_ticks',
'type' => 'checkbox_list',
'options' => [
'empty' => __( 'empty', 'your-text-domain' ),
'dangerous-goods' => __( 'Dangerous goods', 'your-text-domain' ),
],
'inline' => true,
'class' => 'ws-getprice-ticks',
],
[
'name' => __( 'UN Number', 'your-text-domain' ),
'id' => $prefix . 'ws_getprice_un_number',
'type' => 'text',
'placeholder' => __( 'UN0000', 'your-text-domain' ),
'tooltip' => [
'icon' => 'dashicons-info',
'position' => 'top',
'content' => 'Please provide the UN number',
],
'class' => 'ws-getprice-un-number',
'hidden' => [
'when' => [['ws_getprice_ticks', 'not contains', 'dangerous-goods']],
'relation' => 'or',
],
],
],
],
[
'name' => __( 'Your Email', 'your-text-domain' ),
'id' => $prefix . 'ws_getprice_email',
'type' => 'email',
'desc' => __( 'Your e-mail will only be used for this purpose. Read our privacy policy for how we take care of your data.', 'your-text-domain' ),
'placeholder' => __( '[email protected]', 'your-text-domain' ),
'size' => 4,
'required' => true,
],
[
'name' => __( 'Additional Information (Optional)', 'your-text-domain' ),
'id' => $prefix . 'ws_getprice_additional_information',
'type' => 'textarea',
'class' => 'ws-getprice-additional-information',
],
],
'validation' => [
'rules' => [
$prefix . 'ws_getprice_from' => [
'required' => true,
],
$prefix . 'ws_getprice_to' => [
'required' => true,
],
],
'messages' => [
$prefix . 'ws_getprice_from' => [
'required' => 'Origin is required',
],
$prefix . 'ws_getprice_to' => [
'required' => 'Destination is required',
],
],
],
];
return $meta_boxes;
}
Hope you can help me with this.
Hi Kirb,
The group
field is a cloneable group, you need to create a for loop to iterate through the array of items. Or access a specific group item via the key. Like this
$ws_getprice_container_type_group = empty( $group = $_POST['ws_getprice_container_type_group'] ) ? null : $_POST['ws_getprice_container_type_group'];
// access group item via the array key
$ws_getprice_container_type_select = $group[0]['ws_getprice_container_type_select'];
// or use the loop
foreach ( $group as $group_item ) {
echo $group_item['ws_getprice_container_type_select'];
}