我正在尝试设置一个前端帖子提交表单。我得到一个错误:
Warning: Cannot modify header information - headers already sent by (output started at /home/sadlight/public_html/members/wp-content/themes/default-child/announcement-submit.php:1) in /home/sadlight/public_html/members/wp-includes/pluggable.php on line 876
公告提交。php是我下面的模板。我试过了this solution, 但是不行。
此外,当我在下面的代码中使用wp\\u重定向时,它会插入两篇文章,而不是一篇。当我移除它时,它只进入一个。任何帮助都会很好!
仅供参考:我正在使用buddypress和默认的buddypress主题。
<?php
/*
* Template Name: Announcement Submit
*/
$postTitleError = \'\';
if ( isset( $_POST[\'submitted\'] ) ) {
if ( trim( $_POST[\'postTitle\'] ) === \'\' ) {
$postTitleError = \'Please enter a title.\';
$hasError = true;
}
}
get_header(); ?>
<div id="content">
<div class="padder">
<form action="" id="primaryPostForm" method="POST">
<fieldset>
<label for="postTitle"><?php _e(\'Post Title:\', \'framework\') ?></label>
<input type="text" name="postTitle" id="postTitle" class="required" value="<?php if ( isset( $_POST[\'postTitle\'] ) ) echo esc_attr( stripslashes( $_POST[\'postTitle\'] ) ); ?>" />
</fieldset>
<fieldset>
<?php wp_editor( \'Testing some content\', \'postcontent\'); ?>
</fieldset>
<fieldset>
<?php wp_nonce_field( \'post_nonce\', \'post_nonce_field\' ); ?>
<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit"><?php _e(\'Add Post\', \'framework\') ?></button>
</fieldset>
</form>
<?php if ( $postTitleError != \'\' ) { ?>
<span class="error"><?php echo $postTitleError; ?></span>
<div class="clearfix"></div>
<?php } ?>
<?php
if ( isset( $_POST[\'submitted\'] ) && isset( $_POST[\'post_nonce_field\'] ) && wp_verify_nonce( $_POST[\'post_nonce_field\'], \'post_nonce\' ) ) {
if ( trim( $_POST[\'postTitle\'] ) === \'\' ) {
$postTitleError = \'Please enter a title.\';
$hasError = true;
}
$post_information = array(
\'post_title\' => wp_strip_all_tags( $_POST[\'postTitle\'] ),
\'post_content\' => wp_kses_post( $_POST[\'postcontent\'] ),
\'post_type\' => \'post\',
\'post_status\' => \'pending\'
);
wp_insert_post( $post_information );
}
$post_id = wp_insert_post( $post_information );
if ( $post_id ) {
wp_redirect( home_url() );
exit;
}
?>
</div><!-- .padder -->
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>