change value of fields created with advanced custom fields in the front

admin2025-01-07  5

I created a field to enter whatsapp number in the front of a site in wordpress, since the back is simple, but I need to change it from the front section for the users

I have already placed an input where I show the user's information, the other fields already come by default in the subject.

<div class="form-group">
  <div class="stm-label h4"><?php esc_html_e('Whatsapp', 'motors'); ?></div>
   <?php $author_id = get_the_author_meta('ID');
                       $author_badge = get_field('n_whatsapp', 'user_'. $author_id );
                      ?>
        <input class="form-control" type="text" name="stm_phone"
                               value="<?php echo esc_attr($author_badge); ?>"
                               placeholder="<?php esc_html_e('Incluir whatsapp', 'motors'); ?>"/>
                </div>
                <input type="text" id="id_whatsapp" name="acf[n_whatsapp]" value="acf[n_whatsapp]">
                <?php acf_form(); ?>
              </div>
            </div>

I created a field to enter whatsapp number in the front of a site in wordpress, since the back is simple, but I need to change it from the front section for the users

I have already placed an input where I show the user's information, the other fields already come by default in the subject.

<div class="form-group">
  <div class="stm-label h4"><?php esc_html_e('Whatsapp', 'motors'); ?></div>
   <?php $author_id = get_the_author_meta('ID');
                       $author_badge = get_field('n_whatsapp', 'user_'. $author_id );
                      ?>
        <input class="form-control" type="text" name="stm_phone"
                               value="<?php echo esc_attr($author_badge); ?>"
                               placeholder="<?php esc_html_e('Incluir whatsapp', 'motors'); ?>"/>
                </div>
                <input type="text" id="id_whatsapp" name="acf[n_whatsapp]" value="acf[n_whatsapp]">
                <?php acf_form(); ?>
              </div>
            </div>
Share Improve this question edited Jan 17, 2019 at 13:49 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jan 17, 2019 at 13:16 develop12develop12 112 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

If you want to include your own inputs on the acf_form() you should use some of its parameters to allow the form submit them. Otherwise your inputs will be out of the form. As an example you could use this code:

<?php
acf_form(
       array(
                'html_after_fields' => '<input type="text" id="id_whatsapp" name="acf[n_whatsapp]" value="acf[n_whatsapp]">',
            )
        );
?>

You can check all the parameters acf_form() accepts here: https://www.advancedcustomfields.com/resources/acf_form/

Hope this helps.

You are missing the arguments array from ac_form function. You can show the acf fields by using fields attribute. You can pass one or more keys of the acf fields to show in the form.

You can also use field_groups attribute if you want to show whole fields of the group in the form. Acf save function will automatically saved the value after submission of the form.

For arguments of the array passed into the acf_form please see the documentation => https://www.advancedcustomfields.com/resources/acf_form/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736264881a1001.html

最新回复(0)