I am trying to output acf_form() from a shortcode.
function zUpdate( $atts, $content = null ) {
$current_id = get_current_user_id();
$user_id = 'user_' . $current_id;
$options = array(
'post_id' => $user_id,
/* my field group grabs unit, home phone, and cell phone acf */
'field_groups' => array('3307', ),
'submit_value' => 'Update'
);
$form = acf_form( $options );
return $form;
}
when I do this it adds it above or outside the WYSIWYG editor on front end. Should I not return $form and do this some other way. For example I put the shortcode in the WYSIWYG editor in a section tag. it never showed up inside the section but above it. this might be me fundamentally not understanding how shortcodes work if so I apologize.
The problem is that ACF outputs the form when the shortcode is run and what you need it to do is return the value. To do this you use a PHP output buffer
// before you generate form
ob_start();
$current_id = get_current_user_id();
$user_id = 'user_' . $current_id;
$options = array(
'post_id' => $user_id,
/* my field group grabs unit, home phone, and cell phone acf */
'field_groups' => array('3307', ),
'submit_value' => 'Update'
);
acf_form( $options );
// after your code
$form = ob_get_clean();
return $form;