Solved

Form handler redirect question

Posted on 2004-08-18
8
329 Views
Last Modified: 2013-12-13
I have a PHP form handler page with this line of code:

$required_errorpage = "../thank_you_error.html";

Is there any way to turn it into an if then else redirect based on where the submit page came from?  In other words, there are two forms and they both go to this page which does all the form handling.

For the error, I would like the page go to 2 different error pages based on which form was submitted.

the other error page would be "../offer_error.html"

I am using "dynaform" so I don't know if any custom code will work with it. I know very little about PHP so this solution works great other than this issue here. here is the URL for the dynaform site if that helps:
http://www.webligo.com/products_dynaform.php

-- Dan
0
Comment
Question by:danomatic
  • 5
  • 2
8 Comments
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
There are several ways.

1 - Look at the referrer.
2 - Add a hidden field.

e.g

1

switch($_SERVER["HTTP_REFERER"])
      {
      case 'http://site1.com/page1.html':
            $required_errorpage = 'error1.html';
            break;
      case '...' :
            ...;
            break;
      default :
            $required_errorpage = 'defaulterror.html';
      }

or

2 For each form you want a separate error page ...

<input type="hidden" name="new_error_page" value="new_error.html">

and then in the handler php file ...

$required_errorpage = 'defaulterror.html';
if (isset($_POST['new_error_page']) && file_exists($_POST['new_error_page'] . 'html'))
      {
      $required_errorpage = $_POST['new_error_page'] . 'html';
      }


Of course, you may be using $_GET rather than $_POST.

Richard.
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Just checking the dynaform code.

Can you try in the dynaform code, change ...

$required_on = "yes";

and on the forms ...

<input type="hidden" name="required_errorpage" value="your_error_page.html">

Richard.
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
If this does not work, then change the $required_on back to the value already present and then alter ...

$required_errorpage = "error.html";

to

$required_errorpage = "error.html";
if (isset($_POST['new_error_page']) && file_exists($_POST['new_error_page'] . 'html'))
     {
     $required_errorpage = $_POST['new_error_page'] . 'html';
     }

This is not very secure, so try this ...

<input type="hidden" name="whicherrorpage" value="1">

in the form, changing the value for each form and then ...

$required_errorpage = "error.html";
$aOtherErrors = array('page for error 0.html','page for error 1.html');
if (isset($_POST['whicherrorpage']) && isset($aOtherErrors[$_POST['whicherrorpage']]))
     {
     $required_errorpage = $aOtherErrors[$_POST['whicherrorpage']];
     }

Richard.

I think that just about covers it!
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Author Comment

by:danomatic
Comment Utility
RQuadling:

How do I indicate to go up a directory with the error page:

$aOtherErrors = array('page for error 0.html','page for error 1.html');

would it be:

$aOtherErrors = array('page for error ../0.html','page for error ../1.html');
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 500 total points
Comment Utility
../page for error 1.html

Ideally, you should not use relative pages.

Maybe have an /errorpages directory, so no matter where in the structure you are, the errors are ALWAYS in the same place.

$required_errorpage = "error.html";
$aOtherErrors = array('page for error 0.html','page for error 1.html');
if (isset($_POST['whicherrorpage']) && isset($aOtherErrors[$_POST['whicherrorpage']]))
     {
     $required_errorpage = '/errors/' . $aOtherErrors[$_POST['whicherrorpage']];
     }

for example.

Richard.
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Anything else?
0
 
LVL 3

Author Comment

by:danomatic
Comment Utility
I am sorry, I have gotten held up on this project, I will resume this week.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now