When you get those “headers already sent” messages, it is usually one of several things:
-
You are
echo
ing something when you shouldn’t be, which is any time beforeget_header
on the front end. I can’t remember exactly where the window is on the backend. -
You are doing something that is triggering a warning or notice that is printing content too soon. Things like
if ( $_FILES ) {
, while very common, will trigger notices if that variable is not set, and if those print to the screen you haveecho
ed content whether you meant to or not. You should be using!empty($_FILES)
or!isset($_FILES)
to check the variable. -
You are attempting to redirect too late– after the headers have been sent. Usually this means redirecting after
get_header
.
I see wp_header
after your redirect so I expect that the problem is one of the first two possibilities.
As far as your visitors loosing form data, you have that $_POST
data. Use it to repopulate the form on failure. This part is really just an HTML question but supply your input
s with value
attributes.
<input type="text" id="user_submitted_tags" name="user_submitted_tags" value="<?php if (!empty($_POST['user_submitted_tags'])) echo esc_attr($_POST['user_submitted_tags'])">
Again, not really a WordPress question but to provide your notices, set a variable then echo it conditionally.
else {
//Notify the user that they must fill out all required fields
$notice="Fill stuff out";
}
Then in the form somewhere
if (!empty($notice)) {
echo $notice;
}