Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Paul Murphy
6,162 PointsEmail sign-up & redirecting
Hi,
I'm creating a webform for visitors to sign up to our product offers.
What I would like to know is if it is possible for users to be redirected back to the page they signed up from once they have hit submit and are on the "thank you for signing up page".
Ideally I would like this process to be automatic but appreciate I'm fairly limited with HTML as from what I can gather this process is usually operated by PHP/JS.
Any help would be appreciated.
Thanks!
3 Answers
Andrew Larson
12,912 PointsForms are a highly interactive item, if I'm taking too many liberties with the information provide let me know. I'm imagining that you're wanting the information provided chiefly the email address to be submitted to a database so that it can be tracked and used to provide offers now and in the future. To achieve this securely you will need to use a combination of an interaction language (used for real-time validation) JavaScript / jQuery and server side validation using PHP / ASP.NET / etc.
Ignoring the interaction / server side for the moment, in the form tag you'll include as the action the file that will load on submit.
<form method="post" action="signup.htm">
The action property tells the browser what file to load after you press submit. The signup.htm file needs to include within it the actions that need to be taken with the data that was submitted with the form, in most cases you'd use a PHP file on submit to validate the information and post it to a database and or send information back to the user. When dealing with forms it is recommended to only load the success page after server side validation has occurred such as including it at the end of a PHP validation page. To add a more user friendly experience it's also recommended to use in addition to server side validation JavaScript/jQuery to provide real-time validation to the page before submitting.
Paolo Scamardella
24,828 PointsIn PHP, you could use the header() method
http://php.net/manual/en/function.header.php
/* Redirect browser */
<?php
header("Location: http://example.com/");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
In JavaScript, you could use
http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page
// similar behavior as an HTTP redirect
window.location.replace("http://example.com");
// similar behavior as clicking on a link
window.location.href = "http://example.com";
Oğulcan Girginc
24,848 PointsHi Paul Murphy,
If you know PHP, I would suggest looking to Adding a Contact Form under Build a Simple PHP Application.
Paul Murphy
6,162 PointsPaul Murphy
6,162 PointsHi Andrew,
Thank you for the thorough response.
I have a form embedded into a htm file with the code as follows:
This code was mainly supplied by the CRM system we use. Contacts would be automatically dropped into the CRM on subscribing, what I would like is a redirect from thank-you.html back to the last page visited. Is this possible?
Thanks!