[Gloucs] problem with php

rob at cmsnet.org.uk rob at cmsnet.org.uk
Tue Apr 19 14:16:38 BST 2005


Quoting rob at cmsnet.org.uk:

Sorry, I misread your post. You're trying to redirect to another script after
processing the form. Your form variables get lost as the you're sending a
header back to the browser, which then requests test2.php.

You can solve this easily in ASP using Server.transfer(), but I don't think
there's an equivalent in PHP.

Like someone already suggested, you can add you form variables onto a URL with
querystring (e.g. test2.php?personal[name]=dave&personal[email]=dave at dave.com)
and redirect to that. Alternatively, you can print out a page like this:

<html>
<body onload="document.forms[0].submit()">
<form method="post" action="test2.php">
<input type="hidden" name="personal[name]" value="dave"/>
<input type="hidden" name="personal[email]" value="dave at dave.com"/>
</form>
</body>
</html>

This form will submit as soon as the browser loads it, assuming you have
javascript turned on. It's a bit of a kludge.

Another option is to include the second script into your first, and put it
inside a function or conditional block.

There are a couple of similar solutions in this thread:
http://www.zend.com/phorum/read.php?num=6&id=2304&loc=0&thread=2304

> Hiya
>
> Quoting stilman davis <stilman.davis at telinco.co.uk>:
>
> <snip>
>
> > However if I cut it into two pages, test1.php
> >
> > <?php
> > if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
> > header("Location: test2.php");
> > exit();
> > } else {
> > ?>
> > <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
> >  Name:Â  <input type="text" name="personal[name]" /><br />
> >  Email: <input type="text" name="personal[email]" /><br />
> >  Beer: <br />
> >  <select multiple name="beer[]">
> >  <option value="warthog">Warthog</option>
> >  <option value="guinness">Guinness</option>
> >  <option value="stuttgarter">Stuttgarter Schwabenbräu</option>
> >  </select><br />
> >  <input type="hidden" name="action" value="submitted" />
> >  <input type="submit" name="submit" value="submit me!" />
> > </form>
> > <?php
> > }
> > ?>
>
> I think you need to change the form line to be:
> <form action="test2.php" method="post">
>
> > and test2.php
> >
> > <?php
> >  echo '<pre>';
> >  print_r($_POST);
> >  echo '<a href="'. $_SERVER['PHP_SELF'] .'">Please try again</a>';
> >  echo '</pre>';
> > ?>
> >
> > None of the posted values are seen in test2.php (I am assuming that
> > print_r($_POST) will print out all the keys and values posted as it did
> > in the first working example).

<snip>

> > Thank you for your help.
> > Stilman Davis
>
> Rob
Rob






More information about the gloucs mailing list