1

I have a php page that has a form that asks for an e-mail. When you press the send button, it gets to another php page, which gets the form data and does its stuff. I need to then be able to go back to the old page (the one that contained the form) and give it some data so that it will be able to change itself and say "You've sent your e-mail successfully, and will not display the form. How do I do it?

4 Answers 4

2

Sessions probably

https://www.php.net/manual/en/book.session.php

Sign up to request clarification or add additional context in comments.

Comments

0

You can either use sessions or cookies, to not depend on the URL cookies have always to be enabled.

Check the PHP Manual (Sessions and Cookies).

Comments

0

Options:

1) Set a cookie (or use a session variable, which is kind of the same thing)

2) Use a separate thank-you page. After you've processed the form, redirect to http://www.mysite.com/thankyou

3) Process the form on the same page as itself. If your form is at http://www.mysite.com/myform, then at the top of that page have a little

if ($_POST)
  // process form
  // display thank you
else
  // display form

Good luck!

Comments

0

If the user is just seeing data that they've entered anyway, you can just use hidden form fields:

<input type="hidden" id="lang" name="lang" value="en" />

That way you can continue to POST new forms and pass the data down the lane. That's the easiest thing to do without having to write a single extra line of PHP code.

You could also store each section in a database and save each section as-added. That would give you the added benefit of having partial data in the case of a browser crash or whatever, depending on how many parts your form is. You could then pass just an ID to the DB table row and retrieve the data for display.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.