• Resolved nathan005

    (@nathan005)


    was working to build a plugin to display forms, because I want to prefill logged in user data.

    All I have now is super basic

    function myplugin_forms_func() {
    	
    	$html = '';
    		
    	$args = array(
    		'honeypot' => true,
    	);
    	
    	$connectForm = advanced_form( 'form_ID', $args );
    	
    	
    	$html .= '
    		<div class="connect-form">'
    				. $connectForm .
    		'</div>';
    
    	return $html;
    }
    
    add_shortcode('myplugin_forms', 'myplugin_forms_func');

    When I run the shortcode [myplugin_forms] it displays the form where it should be displayed and also at the top of the page as the first item.

    Am I missing something?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nathan005

    (@nathan005)

    I am getting this warning when debug is on

    “Warning: session_start(): Cannot start session when headers already sent in /homepages/16/d612443574/htdocs/myTheme/wp-content/plugins/advanced-forms/api/api-submissions.php on line 39”

    Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi, Nathan!

    The advanced_form function by default echoes the form contents out. What you want to do is to stop this echoing, something like this:

    
    function myplugin_forms_func() {
    	
    	$html = '';
    		
    	$args = array(
    		'honeypot' => true,
                    'echo' => false,
    	);
    	
            $connectForm = advanced_form( 'form_ID', $args );
    	
    	$html .= '
    		<div class="connect-form">'
    				. $connectForm .
    		'</div>';
    
    	return $html;
    }
    
    add_shortcode('myplugin_forms', 'myplugin_forms_func');
    

    I think this is probably also the issue causing your second warning!

    Thread Starter nathan005

    (@nathan005)

    I was just thinking about it and realized I didn’t check what the call returned.

    Just assumed it was html – absolutely my fault.
    I’ll knock it out tomorrow.

    Thanks for the quick response!

    Edit – just added the line with my phone: worked like a charm. Thanks.

    • This reply was modified 5 years, 4 months ago by nathan005.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Form displaying Twice’ is closed to new replies.