Oi tenho esse código abaixo onde coloco no plugin Custom css-js-php que emula um shortcode.
Onde esse shortcode e carregado em um formulário.
Até ai tudo bem, porém quando escrevo alguma coisa no shortcodee crio ou atualizo o formulário. Não e passado para database.
o que eu posso fazer?

     <?php


    /**
     * Add the input field to the form
     *
     * @param int $form_id
     * @param null|int $post_id
     * @param array $form_settings
     */



    $cats = get_product_cats(2270);

            if ($cats) {
                $cat = $cats[0];
                $cat_id = $cat->term_id;
            }
    ?>

    <div>
                            <?php if ($cat) {
                                // get cat groups
                                $groups = get_dolar_cat_groups($cat_id);
                                $groups_data = get_dolar_groups_data();
                                $attrs_data = get_dolar_attributes_data();

                                if (dolar_is_array($groups)) {
                                    $count = 0; ?>
                                    <ul class="dolar-data-pils">
                                        <?php foreach ($groups as $group) { ?>
                                            <li data-pil="#dolar-pil-<?php echo $group; ?>"<?php if ($count == 0) echo ' class="active"'; ?>><?php echo $groups_data[$group]['name']; ?></li>
                                        <?php $count++;
                                    } ?>
                                </ul>

                                <div class="dolar-pil-container">
                                    <?php $count = 0;
                                    foreach ($groups as $group) {
                                        $group_data = $groups_data[$group];
                                        $group_values = get_dolar_product_attributes($post->ID, $group); ?>
                                        <div id="dolar-pil-<?php echo $group; ?>" class="dolar-pil-content<?php if ($count == 0) echo ' active'; ?>">
                                            <?php if ($group_data['attrs']) { ?>
                                                <div class="dolar-group-inputs">
                                                    <ul class="dolar-input-filelds">
                                                        <?php if (dolar_is_array($group_data['attrs'])) {
                                                            foreach ($group_data['attrs'] as $attr_id) {
                                                                $attr = $attrs_data[$attr_id];
                                                                $attr_val = (isset($group_values[$attr_id])) ? $group_values[$attr_id] : ''; ?>
                                                                <li>
                                                                    <div class="dolar-col-1">
                                                                        <label for="attr-input-<?php echo $attr_id; ?>"><?php echo $attr['name']; ?></label>
                                                                    </div>
                                                                    <div class="dolar-col-5">
                                                                        <?php // switch the input types
                                                                        switch ($attr['meta']['type']) {
                                                                            case 'text' :
                                                                                // make text input field
                                                                                echo '<input type="text" id="attr-input-' .$attr_id .'" name="dolar-attr[' .$group .'][' .$attr_id .']" class="dolar-text-input" value="' .$attr_val .'" />';
                                                                            break;

                                                                            case 'check' :
                                                                                // make checkbox input field
                                                                                echo '<input type="hidden" name="dolar-attr[' .$group .'][' .$attr_id .']" value="No" />';
                                                                                echo '<input type="checkbox" id="attr-input-' .$attr_id .'" name="dolar-attr[' .$group .'][' .$attr_id .']" class="dolar-checkbox" value="Yes"' .(($attr_val == 'Yes') ? ' checked="checked"' : '') .' />';
                                                                            break;

                                                                            case 'date' :
                                                                                // make date input field
                                                                                echo '<input type="text" id="attr-input-' .$attr_id .'" name="dolar-attr[' .$group .'][' .$attr_id .']" class="dolar-date-input dolar-text-input" value="' .$attr_val .'" />';
                                                                            break;

                                                                            case 'textarea' :
                                                                                // make textarea input field
                                                                                echo '<textarea id="attr-input-' .$attr_id .'" name="dolar-attr[' .$group .'][' .$attr_id .']" class="dolar-textarea" rows="4">' .$attr_val .'</textarea>';
                                                                            break;

                                                                            case 'select' :
                                                                                // make select box
                                                                                echo '<div class="dolar-select-label"><select id="attr-input-' .$attr_id .'" name="dolar-attr[' .$group .'][' .$attr_id .']" class="dolar-select-box">';
                                                                                foreach ($attr['meta']['options'] as $option) {
                                                                                    echo '<option value="' .$option .'"' .(($option == $attr_val) ? ' selected="selected"' : '') .'>' .$option .'</option>';
                                                                                }
                                                                                echo '</select></div>';
                                                                            break;

                                                                            case 'mselect' :
                                                                                // make multi select box
                                                                                $attr_val = (array) $attr_val;
                                                                                echo '<select id="attr-input-' .$attr_id .'" name="dolar-attr[' .$group .'][' .$attr_id .']" size="' .count($attr['meta']['options']) .'" class="dolar-select-box" multiple>';
                                                                                foreach ($attr['meta']['options'] as $option) {
                                                                                    echo '<option value="' .$option .'"' .((in_array($option, $attr_val)) ? ' selected="selected"' : '') .'>' .$option .'</option>';
                                                                                }
                                                                                echo '</select>';
                                                                            break;
                                                                        } ?>
                                                                    </div>
                                                                </li>
                                                            <?php }
                                                        } ?>
                                                    </ul>
                                                </div>
                                            <?php } ?>
                                        </div>
                                        <?php $count++;
                                    } ?>
                                </div>
                            <?php } else { ?>
                                <p><?php _e('No Groups found for this category, you may add groups by editing category.', 'dolar-text'); ?></p>
                            <?php }
                        } else { ?>
                            <p><?php _e('Please select a Category to continue.', 'dolar-text'); ?></p>
                        <?php } ?>
                    </div>


    <?php





        $dolar_attr = (isset($_POST['dolar-attr'])) ? $_POST['dolar-attr'] : array();

            foreach ($dolar_attr as $key => $group) {
                $attr_data = array();
                foreach ($group as $attr_key => $attr_val) {
                    $attr_data[$attr_key] = esc_textarea($attr_val);
                }

                // save data in post meta fields
                update_post_meta( $post_id, 'dolar-attr-group-' .$key, $attr_data );
            }


?>

Desde já agradeço

Read more here: Shortcode e database


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: