11 Replies - 1005 Views - Last Post: 03 February 2013 - 11:43 PM Rate Topic: -----

#1 slappy5star  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 02-November 12

Two part form in PHP

Posted 02 February 2013 - 05:45 AM

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!

Is This A Good Question/Topic? 0
  • +

Replies To: Two part form in PHP

#2 slappy5star  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 02-November 12

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.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Two part form in PHP

Posted 02 February 2013 - 06:01 AM

1.
echo '<a href="name_of_previous_page.php" class="button">Back</a>';


2.
include "main_page.html";

Was This Post Helpful? 1
  • +
  • -

#4 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,510
  • Joined: 12-December 12

Re: Two part form in PHP

Posted 02 February 2013 - 06:04 AM

View Postslappy5star, 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.
Was This Post Helpful? 1
  • +
  • -

#5 slappy5star  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 02-November 12

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?

This post has been edited by Dormilich: 02 February 2013 - 06:38 AM
Reason for edit:: removed quote

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,510
  • Joined: 12-December 12

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.

This post has been edited by andrewsw: 02 February 2013 - 06:38 AM

Was This Post Helpful? 0
  • +
  • -

#7 slappy5star  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 02-November 12

Re: Two part form in PHP

Posted 02 February 2013 - 06:40 AM

I went with a link! Working as advertised, thanks so much.
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,594
  • Joined: 08-August 08

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";
}

Was This Post Helpful? 1
  • +
  • -

#9 goku87  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 80
  • Joined: 17-October 09

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");

Was This Post Helpful? 0
  • +
  • -

#10 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

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

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

Was This Post Helpful? 0
  • +
  • -

#11 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

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 Java​Script enabled/support.
Was This Post Helpful? 1
  • +
  • -

#12 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1