Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 1st, 2004, 12:23 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default jsp:forward equivalent

I need to take form data parse it into hidden form fields and then send it off to another page. Is there a way to do it without having to push a submit button? Obviously I need a submit button on the form page but I need a second processing page. I don't want to use any javascript. Something in php similar to a jsp:forward. This could even be a dummy html tag that I don't know. My html skills are lacking.

Thanks,
Leo

Reply With Quote
  #2 (permalink)  
Old April 3rd, 2004, 08:25 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I can't think of anything that can do this on the client-side without adding JavaScript.

On the server-side, OTOH, you could store data in session variables. Sessions allow data to persist across multiple connections.

Here's a quick tutorial:

<?php
    // page1.php
    session_start();

    $_SESSION['foo'] = 'Hello, world!';

    echo '<a href="page2.php?sid='.session_id().'">Go to the next page</a>';
?>

<?php
    // page2.php

    session_start();

    if (isset($_SESSION['foo']))
    {
        echo $_SESSION['foo'];
    }
?>

Basically any page that needs to access session data must make a call to session_start() at the beginning of the script. session_start() must be called before any output from the script, since it makes changes to the HTTP headers.

The session id must be passed between any page that requires sessions, you can do that with the get method, as I have above. Or with the post method. By default session_start() also outputs a cookie containing the session id (this is the HTTP header change I mentioned).

Sessions are stored in a file on the server, but within a script you may set them using assignment and unset them using unset(), as you would with any other variable.

Here's the PHP manual page on sessions:
http://www.php.net/session

If you need to see more examples check out google:
http://www.google.com/search?q=php+session+tutorial

hth,
: )
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
  #3 (permalink)  
Old April 7th, 2004, 04:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not terribly familiar with JSP's jsp:forward command, but I gather it works in a manner similar to if you were to rewrite the $_POST array back into the header using PHP's header() function before adding the "header(location: page.ext);" directive.

That's another option, of course, but personally I agree with Richard: the use of sessions is almost certainly preferable. Passing around stuff in hidden fields is only really feasable while there are only a few values to pass around: and if there are only a few values to pass around, why not use a session to pass them around?

It is true that the broken system of session management that Microsoft used in ASP did a lot to make web developers steer shy of sessions, but PHP's system is much more robust.

Dan
Reply With Quote
  #4 (permalink)  
Old April 7th, 2004, 04:19 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another option is available if you don't need to explicitly make a new request (e.g., the page you're redirecting to is on the same server), you can also just include the PHP script you want to redirect to.


<?php // page_1.php

$some_var = "some value";

include ("page_2.php"); // executes page_2 with $some_var in global scope

?>

Bear in mind that sessions only work for the same site as well, so if you're posting form data to another site, then you'll need to use a client-side solution like javascript.

Generate an HTML form with all the appropriate values populated. Then have javascript submit the form in the onLoad event.

<body onLoad="javascript:document.myform.submit();">

<p>
  Please wait while you are redirected.
  If you are not redirected within 5 seconds, click
  <a href="javascript:document.myform.submit();">here</a>.
</p>
<form name="myform" method="post" action="some_other_page">
  <input type="hidden" name="whatever" value="some value" />
  ...
</form>
</body>


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #5 (permalink)  
Old May 19th, 2004, 03:16 PM
Registered User
 
Join Date: May 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[quote]Originally posted by Daniel Walker
 ...rewrite the $_POST array back into the header using PHP's header() function before adding the "header(location: page.ext);" directive.

Daniel, can you give an example of a header command that rewrites $_POST array back in? This is exactly what I need to do. My initial attempts have failed...

Thanks,
Gail
Reply With Quote
  #6 (permalink)  
Old May 19th, 2004, 04:18 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:Originally posted by gailp
Daniel, can you give an example of a header command that rewrites $_POST array back in? This is exactly what I need to do. My initial attempts have failed...
From what I've read that isn't possible.

Here's a few URLs on the topic..
http://ppewww.ph.gla.ac.uk/~flavell/...-redirect.html
http://www.webmasterworld.com/forum13/598.htm
http://www.webmasterworld.com/forum88/2365.htm

hth!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
  #7 (permalink)  
Old May 19th, 2004, 07:17 PM
Registered User
 
Join Date: May 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by richard.york
 From what I've read that isn't possible.
Richard, thank you for those urls!!! It was driving me nuts not to understand what the problem was. Interesting to learn that POST data is not sent in the headers!

Gail
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to forward some action from javascritp msg2ajay Javascript 1 September 3rd, 2007 09:08 AM
jsp:forward problem rushman Pro JSP 1 October 24th, 2005 10:36 AM
Forward after Login ~Bean~ ASP.NET 1.0 and 1.1 Basics 1 July 14th, 2005 05:14 PM
Forward booking rahilahmed Pro VB Databases 1 June 16th, 2004 06:02 PM
Forward Booking rahilahmed Excel VBA 0 May 24th, 2004 09:25 AM



All times are GMT -4. The time now is 01:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.