Support

Account

Home Forums Front-end Issues Front End update form

Solved

Front End update form

  • Hello

    I want to use the acf_form () fornction to perform CPT data modification with ACF fields.

    I followed the doc but my modifications do not register …
    For info I put in the header of the page index.php

    acf_form_head ();
    get_header ();

    and for the part of the corresponding page:

    $current_user_id = get_current_user_id ();
    
    // 1. Define what we want
    $args = array (
    'post_type' => 'member', // CPT name
    
    'meta_key' => 'mb_id_user',
    'meta_value' => $current_user_id,
    'meta_compare' => '='
    );
    
    // 2. Execute the query
    $my_query = new WP_Query ($ args);
    
    // 3. we launch the loop!
    if ($my_query-> have_posts ()): while ($my_query-> have_posts ()): $my_query-> the_post ();
    
    echo '<h3> Professional Information </h3>';
    if (current_user_can ('publish_posts')) {// User role control
    acf_form (array (
    'submit_value' => __ ('Update', 'acf')
    ));
    }
    endwhile;
    endif;

    Did I make a mistake?
    Thanks

  • What modifications are you trying to make?

  • Hello,

    I want people can change their personal information on the form which corresponds to ACF data of a member CPT

  • You need to set the post ID for the post that should be edited otherwise the post IF of the current page is used

    
    acf_form (array (
    'post_id' => $post=>ID,
    'submit_value' => __ ('Update', 'acf')
    ));
    
  • Bonjour,

    je viens de tout reprendre afin de voir ce qui ne marche pas.
    J’ai simplifié au maximum.

    $user_ID = get_current_user_id();
    acf_form(array(
            'field_groups'  => [12495],
            'post_id'       => 'user_' . $user_ID,
            'submit_value'  => __('Mettre à jour', 'acf')
        ));

    J’ai bien ajouté la balise

    acf_form_head ();
    get_header ();

    Les données s’affichent dans mon formulaire.
    Mais l’enregistrement lors de la mise à jour e fonctionne pas et je ne comprends pas pourquoi …

    Voici la structure de mon groupe de champs

    et le rendu visuel

  • I’ll share the solution with you.
    I just understood that in the acf_form () function; you had to pass all the form tags.
    Whose input action
    Here is the script that works to adapt of course to your needs:

    /*====Shortcode contenu News Tab  - ACF  ================= */
    
    add_action( 'admin_post_adaptiveweb_save_profile_form', 'adaptiveweb_save_profile_form' );
    function adaptiveweb_save_profile_form() {
      if(!isset($_REQUEST['user_id'])) return;
    
      do_action('acf/save_post', $_REQUEST['user_id']);
    
      wp_redirect(add_query_arg('updated', 'success', wp_get_referer()));
      exit;
    }
    
    /* Contenu ACF dans Shortcode */
    
    function contenu_shortcode_onglet( $atts ) {
    
    $user_ID = get_current_user_id();
    $user = wp_get_current_user();
    
    $options = array(
        // 'field_groups' => ['group_618a52d0b2b74'],
        
        'fields' => [
            'field_618a52d0b874e',
            'field_618a52d0b878d',
            'field_618a52d0b87ce',
            'field_618a52d0b880f',
            'field_618a52d0b870d',
            'field_618a526a02cd7',
            'field_618a526a02d0f'
    
        ],
    
        'form_attributes' => [
            'method' => 'POST',
            'action' => admin_url("admin-post.php"),
        ],
    
        'html_before_fields' => sprintf(
            '<input type="hidden" name="action" value="adaptiveweb_save_profile_form">
            <input type="hidden" name="user_id" value="user_%s">', $user->ID
        ),
    
        'post_id' => "user_{$user->ID}",
        'form' => true,
        'html_submit_button' => '<button type="submit" class="acf-button button" value="Update Profile">Update Profile</button>',
        'updated_message' => __('<div class="woocommerce-message" role="alert">
            Les détails du compte ont bien été modifiés.</div>', 'acf')
        
    );
    
    acf_form($options);
    
    }
    add_shortcode( 'onglet', 'contenu_shortcode_onglet' );
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.