How to hide page content during redirect after form submit? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Saturday, September 24, 2022

How to hide page content during redirect after form submit?

I have a form that allows the user to change the account avatar, it works quite well. However, when the user clicks on the remove button, a redirect occurs and for a brief moment during the redirect the page layout is all broken.

This is the behavior of the page / url

when click on remove button, the page url goes from mywebsite.com/account/settings to mywebsite.com/account/settings/?rm_profile_image_id= after a few seconds again mywebsite.com/account/settings

When in that brief instant the page loads the url mywebsite.com/account/settings/?rm_profile_image_id= the broken layout is displayed. So, is there a way to hide the contents of this url with Javascript ?

This is the Js code that allows me to remove the avatar

// Delete Avatar
if (isset($_GET['rm_profile_image_id'])) {
   if ($attachment_id == $_GET['rm_profile_image_id']) {
   wp_delete_attachment($attachment_id);
   
   if (delete_user_meta($user_id, 'image')) {
      wp_delete_attachment($attachment_id);
   }

   ?><script>window.location = "https://www.mywebsite.com/account/settings";</script><?php
   exit();
   }
} else {
   echo '<a href=' . wc_get_account_endpoint_url('settings') . '?rm_profile_image_id=' . $attachment_id . '> ' . __('Remove') . ' </a>';
} 


source https://stackoverflow.com/questions/73831717/how-to-hide-page-content-during-redirect-after-form-submit

No comments:

Post a Comment