Support

Account

Home Forums Front-end Issues Custom Genesis user profile page doesn't load after submit

Solved

Custom Genesis user profile page doesn't load after submit

  • I’m following a tutorial from UserInsights and building it into a Genesis child theme.

    The form works well except that it returns a blank page on submit. It seems like a problem with acf_form_head, which I add to ‘get_header’ (instead of ‘wp_head’– because I’m working with Genesis).

    Anyone with Genesis knowledge have an idea why the page fails to load on submit?

    Here’s code from the linked page:

    function my_acf_user_form_func( $atts ) {
     
      $a = shortcode_atts( array(
        'field_group' => ''
      ), $atts );
     
      $uid = get_current_user_id();
      
      if ( ! empty ( $a['field_group'] ) && ! empty ( $uid ) ) {
        $options = array(
          'post_id' => 'user_'.$uid,
          'field_groups' => array( intval( $a['field_group'] ) ),
          'return' => add_query_arg( 'updated', 'true', get_permalink() )
        );
        
        ob_start();
        
        acf_form( $options );
        $form = ob_get_contents();
        
        ob_end_clean();
      }
      
        return $form;
    }
     
    add_shortcode( 'my_acf_user_form', 'my_acf_user_form_func' );
    
    //adding AFC form head
    function add_acf_form_head(){
        global $post;
        
      if ( !empty($post) && has_shortcode( $post->post_content, 'my_acf_user_form' ) ) {
            acf_form_head();
        }
    }
    add_action( 'wp_head', 'add_acf_form_head', 7 );
  • Adding acf_form_head() on the wp_head action is far too late. This action is not called until the last thing before the </head>' tag. The ACF function must be called before any HTML is output.

    This can be done on the init hook for example, or any hook that runs before any content is output.

    For example, you could also use get_header hook https://developer.wordpress.org/reference/functions/get_header/https://genesistutorials.com/visual-hook-guide/

    It is usually most efficient to add the acf_form_head() call before the get_header() call in your template because that way you’re only including the ACF scripts on the pages where they are needed.

    More than likely you’re getting a blank page because there is a php error, probably cannot modify headers, out started at .... error. You might want to turn on error reporting https://codex.wordpress.org/WP_DEBUG

  • You’re right, I’m seeing a conflict with wp-includes/pluggable.php – the last line here:

    $status = apply_filters( 'wp_redirect_status', $status, $location );
    
    	if ( ! $location )
    		return false;
    
    	$location = wp_sanitize_redirect($location);
    
    	if ( !$is_IIS && PHP_SAPI != 'cgi-fcgi' )
    		status_header($status); // This causes problems on IIS and some FastCGI setups
    
    	header("Location: $location", true, $status);

    I also accidentally discovered that if I activate the plugin WP User Frontend, then location works and the form successfully reloads.

    Not sure what the plugin is doing right compared to my code, but I’ll keep digging. I’m using the get_header hook in add_action( 'get_header', 'add_acf_form_head', 7 ); but I’ll try calling it before get_header.

    Thanks for your help, I appreciate it.

  • I’ve got this working and am using it to overwrite user first name, last name, email, and a custom tel. field.

    I see now that the email field doesn’t update the WordPress meta – is it possible to overwrite the standard WordPress meta with the ACF field value?

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Custom Genesis user profile page doesn't load after submit’ is closed to new replies.