?
Solved

Form handler redirect question

Posted on 2004-08-18
8
Medium Priority
?
338 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
7 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
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:Richard Quadling
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:Richard Quadling
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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:
Richard Quadling earned 2000 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:Richard Quadling
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 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