Support

Account

Home Forums Front-end Issues Frontend Form post content editor

Solved

Frontend Form post content editor

  • Hi Elliot,

    I have a frontend form for posting new content type. The post title and description is added by the default wordpress fields. Now I am able to include the post title textfield, but am unable to include the wp_editor() just after the title field. I guess this is because wp_editor does not return anything and renders the TinyMCE editor. How do I achieve this?

    Here is my code below:

    $settings = array(
    			    'textarea_name' => 'content',
    			    'media_buttons' => false,
    			    'quicktags' => false,
    			    'tinymce' => array(
    			        'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
    			            'bullist,blockquote,|,justifyleft,justifycenter' .
    			            ',justifyright,justifyfull,|,link,unlink,|' .
    			            ',spellchecker,wp_fullscreen,wp_adv'
    			    )
    			);
    
    			$options = array(
    			    'post_id' => 'new', // post id to get field groups from and save data to
    			    'field_groups' => array(75), // this will find the field groups for this post (post ID's of the acf post objects)
    			    'form' => true, // set this to false to prevent the <form> tag from being created
    			    'form_attributes' => array( // attributes will be added to the form element
    			        'id' => 'post',
    			        'class' => '',
    			        'action' => '',
    			        'method' => 'post',
    			    ),
    			    'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
    			    'html_before_fields' => '<h2>Add New Post</h2><input type="text" name="post_title" size="30" id="title" placeholder="Enter title here" autocomplete="off"><textarea class="wp-editor-area" style="height: 360px; resize: none; display: none;" cols="40" name="content" id="content" aria-hidden="true"></textarea>' . wp_editor( $content, 'frontendform', $settings ), // html inside form before fields
    			    'html_after_fields' => '', // html inside form after fields
    			    'submit_value' => 'Submit', // value for submit field
    			    'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
    			);
     			if (is_user_logged_in()) {
     				acf_form( $options );
     			}
  • Resolved by using ob_start() and ob_get_clean().

    ob_start();
    wp_editor( $content, 'frontendform', $settings );
    $editor_contents = ob_get_clean();
  • Hi @bekar09

    Thanks for posting the solution!

    yes, for now, this is the only way to accomplish it. I’ll add in some actions so that there is a nicer experience to customize the form elements

    Thanks
    E

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

The topic ‘Frontend Form post content editor’ is closed to new replies.