In simple words I am trying to look for a solution to redirect my page using post method but from with my php code and not setting the action attribute in form tag.
Thanks,
RizwanRedirecting to another page from your PHP code, when you want to GET the new page:
<?php
header("HTTP/1.1 303 See Other");
header("Location: http://www.example.com/page/to/redirect-to.html");
?>
I'm using 303 here, as the HTTP/1.1 spec says:
The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource.
and redirecting using 301, 302 or 307 doesn't always get you a redirect-to-GET.
<form action="<?php echo $_SERVER['PHP_SELF']; ?> action="post">
... rest of form code
for your submit button
<input type="submit" name="formsubmit" value="submit button text" />
Somewhere towards the top of your page
<?php
if(isset($_POST['formsubmit))
{
//do validation and if validated - redirect to new page
}
else {
// display errors and current page with form again
}
?>
精彩评论