Solved

Form handler redirect question

Posted on 2004-08-18
8
330 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
ID: 11839941
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
ID: 11839974
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
ID: 11840009
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:danomatic
ID: 11841601
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
ID: 11850353
../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
ID: 11870239
Anything else?
0
 
LVL 3

Author Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

911 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

20 Experts available now in Live!

Get 1:1 Help Now