RE: Changing the Action attribute of Form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



No problem.

A simple script to do what you want could be:

<?php

if (isset($_REQUEST['test_item']) {
  $test_item = $_REQUEST['test_item'];

  $redirect_page = '';
  switch ($test_item) {
    case '1':
      $redirect_page = 'page1.php';
      break;
    case '2':
      $redirect_page = 'page2.php';
      break;
    default:
      // Handle undefined value of test_item
  }

  $redirect_url = 'http://www.example.com/path/to/' . $redirect_page;
  header('Location:'.$redirect_url);
  exit();
}
// Handle bad form data here
?>

The key is to ensure your script doesn't output anything before the header
function call. This includes and HTML tags or even blank lines. Doing so
will result in a PHP error saying that the headers have already been sent.

A bit more info: http://php.about.com/od/learnphp/ht/phpredirection.htm

Edward

> -----Original Message-----
> From: Sue Kot [mailto:skot1@xxxxxxxxxxxx]
> Sent: 01 November 2006 15:47
> To: Edward Kay
> Subject: Re:  Changing the Action attribute of Form
>
>
> Edward,
>
> Thank-you so much for responding to my question.  I am new to PHP and I'm
> lost as to how you would redirect users using an HTTP header.
> Any examples
> or references that you can provide would be great.  Thanks again!
>
> Sue
>
> ----- Original Message -----
> From: "Edward Kay" <edward@xxxxxxxxxx>
> To: "sues" <skot1@xxxxxxxxxxxx>
> Sent: Wednesday, November 01, 2006 10:28 AM
> Subject: RE:  Changing the Action attribute of Form
>
>
> > Set the action attribute to be the same page as the form (or a separate
> > 'handler' PHP page). This script can then examine the input supplied by
> > the
> > submission and then redirect the user to the appropriate page
> with an HTTP
> > header.
> >
> > I'd avoid using JavaScript for this sort of thing. It can be easily
> > tampered
> > with plus users without JS/JS turned off won't be able to use your site.
> >
> > Edward
> >
> >> -----Original Message-----
> >> From: sues [mailto:skot1@xxxxxxxxxxxx]
> >> Sent: 01 November 2006 15:20
> >> To: php-general@xxxxxxxxxxxxx
> >> Subject:  Changing the Action attribute of Form
> >>
> >>
> >> I need to pass control of a form to either a page that accesses our
> >> database, and displays the data, OR to a page that contains
> >> static content.
> >> The ACTION attribute will then depend on the contents of 1 of the input
> >> fields in the form, which is a SELECT type of input. Here is an
> >> example of
> >> what the form looks like:
> >>
> >> <form id="test" action="some_page.php" method="get" name="test">
> >>  <select name="test_item" size="1">
> >>       <option value="1">Item 1</option>
> >>       <option value="2">Item 2</option>
> >> </select>
> >> <input type="submit" name="submit" value="submit" />
> >> </form>
> >>
> >> If "Item 1" is selected, I want to go to a certain page
> >> (some_page.php), and
> >> if "Item 2" is selected I want to go to a different page.  Is
> >> there a way to
> >> handle this using PHP or JavaScript?  Any help would be greatly
> >> appreciated!
> >>
> >> Thanks!
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >>
> >>
> >
>
>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux