EDIT:
So my remaining questions are: (1) should I use a 302 or 303 for the header() redirect? I believe 303 is the proper way. (2) Is $_SESSION the best way to pass variables to the ?contact=thankyou page?
My revised code:
if ( isset( $_POST[ 'submit' ] ) )
{
if ( is_bot() )
{
header( "Location: http://www.example.com/contact/?contact=thankyou",
TRUE, 303 );
exit;
}
elseif ( is_input_error() )
{
// show error form stuff...
}
else
{
contact_send_email();
header( "Location: http://www.example.com/contact/?contact=thankyou",
TRUE, 303 );
exit;
}
}
ORIGINAL (resolved):
I am just learning about $_POST, $_GET and forms with PHP. I have a Contact Form that started out simple, but has now become a little complicated for my experience.
// curly braces left out for brevity
if ( isset( $_POST[ 'submit' ] ) )
if ( is_bot() )
header( "Location: http://www.example.com/contact/?contact=thankyou",
TRUE, 303 );
if ( is_input_error() )
header( "Location: http://www.example.com/contact/?contact=error",
TRUE, 303 );
else
contact_send_email()
header( "Location: http://www.example.com/contact/?contact=thankyou",
TRUE, 303 );
- Being new at this, I guess I'd like to know if you see any glaring problems?
- Does my
header()
redirect code look complete and valid? - What is the most common and/or recommended way to pass
$_POST
variables after theheader()
redirection? Is it with$_SESSION
, or is there a better way? I've never used sessions before, so I am a little intimidated by them.
EDIT: By the way, I want to pass the header()
redirect with $_GET
to avoid the "refresh-resend" very scary and evil warning message.