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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.