Solved

Form handler redirect question

Posted on 2004-08-18
8
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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 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: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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

726 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