I know this is a stupid question that I should know the answer to. I am trying to set the form on my site to take the user to a page that says "Thank you for your comments." The only problem is that I can only make it submit the form or go to the page, I can't make it do both. Could someone please tell me how to fix this?

Dani AI

Generated

As noted, the element that controls where the browser goes after you click submit is the form action. The usual, reliable way to both process data and show a "Thank you" page is to point action at a server-side processor that handles the POST and then redirects the browser to the thank-you page (the Post/Redirect/Get pattern). That preserves the submitted data, avoids double-posts on refresh, and gives the user a clean thank-you page. See Post/Redirect/Get for the pattern.

Example workflow (simple and robust): the HTML form posts to a processor; the processor validates/saves the input, then sends an HTTP redirect to the static thank-you page. Example processor behaviour (PHP):

<form method="post" action="/process-form.php">
  <input name="name" required>
  <button type="submit">Send</button>
</form>
<?php
// process-form.php
// validate and handle $_POST here
header('Location: /thank-you.html', true, 303);
exit;
?>

If a single-page UX is preferred, submit via AJAX/fetch and then replace the form with a thank-you message or navigate to the thank-you URL. Keep the server-side endpoint working as a fallback so users without JavaScript still submit successfully.

Common pitfalls and quick troubleshooting: if you set action directly to the thank-you HTML you will not process or save the form data. When using server redirects, send headers before any output (see PHP header() docs at https://www.php.net/manual/en/function.header.php). Use browser devtools Network tab to confirm the POST, the server response, and the redirect status (303/302). This resolves the "submit OR go to page" problem that described.

Recommended Answers

All 2 Replies

Set the form action inthe submitting page to the "thank you" page. :)

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.