Jump to content

[SOLVED] Header Redirect + success/error message


xtopolis

Recommended Posts

Hi,

In order to keep a form from being resubmitted by pressing refresh, I tend to post the form, extract/manipulate the post vars, and then use a header redirect back to the same page in order to clear the post stuff and basically start with a 'fresh' version of the form.

 

My question is:  I would like to use this method, but also find a way to return an error/success message.  This is possible using $_GET and attaching things to the url, but IMO that is rather messy, and I would like to avoid it.  Are there alternatives to this to accomplish what I want?

 

Sample code of what I currently do:

<?php
if(isset($_POST['name']))
{
  //do something with the form vals
  Header('Location: ' . $_SERVER['PHP_SELF']);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <input type="text" name="name" /><input type="submit" value="Process" />
</form>

 

Basically if I was inserting into a database, I would like it to have a message saying if it succeeded or failed, while still having the form not being able to just be resubmitted.  (Even if I don't allow it to go through[dupes], I still want it to be handled this way).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.