Hello I’ve a kind that provides attachments to a put up, nevertheless when the shape posts it clearly does not present the put up with the brand new attachment echoing “your file has been uploaded”. When the consumer refreshes the web page (to attempt to present their new attachment) the shape posts once more!
Is it doable to both (1) cease the shape posting once more on refresh, (2) routinely refresh the web page to show the put up with its new attachment?? (2 is approach higher)
<?php $post_id = $post->ID;
if ( isset( $_POST['html-upload'] ) && !empty( $_FILES ) ) {
require_once(ABSPATH . 'wp-admin/consists of/admin.php');
$id = media_handle_upload('async-upload', $post_id); //put up id of Consumer Recordsdata web page
unset($_FILES);
if ( is_wp_error($id) ) {
$errors['upload_error'] = $id;
$id = false;
}
if ($errors) {
echo "<p>There was an error importing your file.</p>";
} else {
echo "<p>Your file has been uploaded.</p>";
}
}
?>
<kind id="file-form" enctype="multipart/form-data" motion="<?php echo $_SERVER['REQUEST_URI']; ?>" technique="POST">
<p id="async-upload-wrap"><label for="async-upload">add</label>
<enter sort="file" id="async-upload" title="async-upload"> <enter sort="submit" worth="Add" title="html-upload"></p>
<p><enter sort="hidden" title="post_id" id="post_id" worth="<?php echo $post_id ?>" />
<?php wp_nonce_field('client-file-upload'); ?>
<enter sort="hidden" title="redirect_to" worth="<?php echo $_SERVER['REQUEST_URI']; ?>" /></p>
<p><enter sort="submit" worth="Save all adjustments" title="save" fashion="show: none;"></p>
</kind>
Thanks! 🙂