i want create action form in same page not with another page to display result or execute php code

this is my code

<?php
$error="";
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ){
if( !empty( $_POST['fn'] ) ){
  update_user_meta( $current_user->ID, 'first_name', esc_attr( $_POST['fn'] ) );
  wp_redirect( get_permalink() );exit;
  }else{
         $error="terjadi kesalahan saat mengedit profile anda";
  }
}
?>
    <form method="post" action="<?php the_permalink(); ?>">
    <div class="alert-error"><?php echo $error;?></div>
    <div class="form-group"><label for="fn">Nama Depan</label>
      <input type="text" class="form-control" id="fn" name="fn" value="<?php the_author_meta( 'first_name', $current_user->ID ); ?>">
    </div>
    <p class="form-submit">
      <?php echo $referer; ?>
      <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Update', 'profile'); ?>" />
      <?php wp_nonce_field( 'update-user' ) ?>
      <input name="action" type="hidden" id="action" value="update-user" />
    </p><!-- .form-submit -->
    </form>

i’am sorry for my bad question, i hope it’s will be perceptibly.

Thanks

Read more here: any alternative to fix "Warning: Cannot modify header information" [duplicate]


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , , ,

Wordpress related questions and answers: