I have created a two part form with PHP / html for registration purposes. Once the user clicks register they are taken to a new page saying that it was successful (or that there was an error). I want to add a button on this second page that would allow the visitor the option of going back to that first page and registering another person. This raises two questions:
1. Is it possible to add html controls (in this case basically a back button) in a PHP script and how could I accomplish this?
2. How do I redirect my visitor back to the main page?
Thanks!
Two part form in PHP
Page 1 of 111 Replies - 267 Views - Last Post: 03 February 2013 - 11:43 PM
Replies To: Two part form in PHP
#2
Re: Two part form in PHP
Posted 02 February 2013 - 05:52 AM
I managed to add the button, so now I am just stuck trying to get it to send the visitor back to the main page.
#3
Re: Two part form in PHP
Posted 02 February 2013 - 06:01 AM
1.
2.
echo '<a href="name_of_previous_page.php" class="button">Back</a>';
2.
include "main_page.html";
#4
Re: Two part form in PHP
Posted 02 February 2013 - 06:04 AM
slappy5star, on 02 February 2013 - 05:52 AM, said:
I managed to add the button, so now I am just stuck trying to get it to send the visitor back to the main page.
You can use the header() method to perform a redirect in PHP. Note that NOTHING must be output before the redirect is issued - not even a space!
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
?>
Alternatively, add an anchor A-tag to the page, or a button and click event, that the user can click.
Don't be tempted to use (Javascript) window.history.back() or window.history.go(-1) as this will re-submit the form.
#5
Re: Two part form in PHP
Posted 02 February 2013 - 06:17 AM
Using this header does work, but it creates a new problem, I no longer get redirected to the confirmation page, the form is simply cleared! (although it is still being submitted).
Any way to fix this?
Any way to fix this?
This post has been edited by Dormilich: 02 February 2013 - 06:38 AM
Reason for edit:: removed quote
#6
Re: Two part form in PHP
Posted 02 February 2013 - 06:37 AM
The PHP/header() info was only in answer to your question about redirecting (with PHP); it won't pause.
You presumably want the other options - buttons or links that wait for the user to click them.
You presumably want the other options - buttons or links that wait for the user to click them.
This post has been edited by andrewsw: 02 February 2013 - 06:38 AM
#7
Re: Two part form in PHP
Posted 02 February 2013 - 06:40 AM
I went with a link! Working as advertised, thanks so much.
#8
Re: Two part form in PHP
Posted 02 February 2013 - 06:41 AM
Using header sends a message back to the browser telling it to try a new site. If that site is yours then you're generating unnecessary web traffic and slowing your server down. Use it sparingly. Your preferred method should be to include. Either way, there should be some conditional so it doesn't always redirect/include:
if($X) {
header('Location: http://www.example.com/'');
exit();
}
if($X) {
include "some_file.php";
}
#9
Re: Two part form in PHP
Posted 02 February 2013 - 07:45 AM
I wish I would have seen this before; might be too little, too late, but I prefer a redirect over a location header. This allows code to be output for debugging, peace of mind, and whathaveyou, so long as the header is declared before any output. You use it exactly like the location header, however you specify the time in seconds after which you want to redirect it to:
header("refresh: 5; url = http://whatever.com");
#10
Re: Two part form in PHP
Posted 03 February 2013 - 09:16 PM
Well, I have a small doubt...will it be ok to use
I remember having used that before when I was unfamiliar with the header method of PHP.
regards,
Raghav
echo '<script type=text/javascript>window.location="something.php"</script>';
I remember having used that before when I was unfamiliar with the header method of PHP.
regards,
Raghav
This post has been edited by raghav.naganathan: 03 February 2013 - 09:17 PM
#11
Re: Two part form in PHP
Posted 03 February 2013 - 11:32 PM
well, in contrast to HTTP or HTML headers (and even to PHP includes), this would only work if the User Agent had JavaScript enabled/support.
#12
Re: Two part form in PHP
Posted 03 February 2013 - 11:43 PM
Yes, thank you for that answer. I wanted to know whether it was the right way to go about it 
regards,
Raghav
regards,
Raghav
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|