Support

Account

Home Forums Front-end Issues Front End and custom user meta Reply To: Front End and custom user meta

  • I am using acf5 beta. The form is displaying on the front end fine, submits and then calls my php script with the acf save function in it.

    The php script called by the form action has the correct array within $_POST so the values are available, just not sure why acf is not saving them.

    1. The form

    <?php get_template_part('templates/wrapper-header'); ?>
    
    	<?php
    	/*
    	When the form is submitted we call this file to deal with it's submission
    	Below we have a function and then a condition to call the function. The conditional is $_POST['submit'] so the function is only called if the form is submitted
    	*/
    	
    	// Get the current user 1
    	$userID = get_current_user_id();
    	?>
    
    	<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
                            
            <h1 class="editor editor-title"><?php the_title(); ?></h1>
            
            <div class="editor editor-content"><?php the_content(); ?></div><!-- end editor -->
            
            <form method="post" action="<?php echo get_template_directory_uri(); ?>/frontend-form-acf-siteaddresses.php">
            
            	<?php
                acf_form(array(
                    'field_groups' => array('1632'), // the ID of the field group (group not field name or key, the entire field group)
    				'post_id' => 'user_'.$userID, // To populate the front end form fields with saved data
                    'form' => false // Don't load the full acf form, just load the fields into my html form
                ));
    			?>
                
                <input type="hidden" name="function" value="ttm_frontend_form_acf_siteaddresses">
    
            	<input type="submit" value="Submit">
    
            </form>
        
        <?php endwhile; ?>
    
    <?php get_template_part('templates/wrapper-footer');

    2. The php script called by the form (this is called correctly and the $_POST variable contains all of the submitted fields)

    <?php require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php'); ?>
    
    <?php
    $userID = get_current_user_id();
    
    // $post_id to save against
    $postID = 'user_' . $userID;
    
    //echo '<pre>';
    //var_dump($fields);
    //echo '</pre>';
    
    // update the post
    do_action('acf/save_post', $postID);
    ?>

    Any ideas?

    Thanks