Reply
Form on multiple pages???? Please help
Old 07-24-2008, 11:38 AM Form on multiple pages???? Please help
Experienced Talker

Posts: 48
I want to build a form that when somebody clicks submit their details are sent to one url, but they are then directed to a different page where they will be able to enter more details and still have the original details retained. I came across this example (although I don't want anyone to have to pay for this.)
At the moment I've got the form on one page:
Code:
<form id="user" name="user" method="get" action="http://www.remotedomain.com/users.php" onsubmit="return validate_form()">
  <br /><label>Full Name
  <input type="text" name="name" id="name" />
  </label><br><label>Number
  <input type="text" name="number" id="number" />
  </label>
  <br /><input name="submit" type="submit" />
  </form>
this is then sent to a remote url. This remote url will then send them a pin number that I want them to add in to the page without having to enter other details again. So I guess I want something like:
Code:
;
<?php
$number = intval($_GET['number']);
?>
<form action="step2.php" method="get" name="name">Please type in your pin number then click Submit.
	  <br>
	    <br><input name="number" type="hidden" value="<? $number ?>"><label>Pin number:<input name="pin" type="text" size="15" maxlength="30" /></label><br /><input name="Submit" type="submit" value="Submit" /></form>
but will this work? Also how do I send the details of the first form to one address while still keeping the user on this page?

Thanks
thehappyappy is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 07-24-2008, 06:45 PM Re: Form on multiple pages???? Please help
Super Talker

Posts: 122
One easy way for this is what I call a "router" page. This page is just a post page, that has a case for each function you need. So say you have it post that form data, it will post to routerpage.php?id=x

where x is your switch statement

then, BEFORE anything is written to the page, I have it do all the functions it needs to do and I create 2 variables.

$responseMessage and $header
header contains the url, and response message is just a message I give after you posted...saying, hey that was wrong, or succeeded, you'll be redirected to $header, click here if you wish not to wait....

heres an example of my code for after the switch (when you write to the body)

HTML Code:
<html>
<head>
<meta http-equiv="refresh" content="3; url=<?php echo $header;?>"/>
</head>

<body>
    <table height="50%" align="center">
        <tr>
            <td valign="bottom">
                <?php echo $responseMessage;?>
                <br /><br /> Please wait while we transfer you.... <br /><br />
                <a href="<?php echo $header;?>">(Or click here if you wish not to wait)</a>
            </td>
        </tr>
    </table>
</body>
</html>
This way, after you execute all the db commands, or anything you need to do, it goes down to the body, and you give the reponse message, and it automatically redirects to the $header url.

OFC you could always just skip the 3 second part and automatically forward them to the page you want them to be at.


Any questions, just ask, Ill be glad to assist as best I can.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 07-25-2008, 05:20 AM Re: Form on multiple pages???? Please help
Experienced Talker

Posts: 48
Thanks for your help. I think I understand what you're saying, but I do have one question though, with the router page is it possible to get it to send the information off the a different url without redirecting the user as well. The reason why I ask is because the user will be sent a pin and need to enter it in to the next part of the form, but the first part sends the request of to the remote url to generate the pin.
Also is the router page written in php as well? I'm quite new to PHP so don't know too much as the moment.
thehappyappy is offline
Reply With Quote
View Public Profile
 
Old 07-25-2008, 07:09 AM Re: Form on multiple pages???? Please help
Super Talker

Posts: 122
ya the router page is written in php.

before I have any html in the router page I just have

switch($_GET['id'])
{
...
...
...
}

and that takes care of the task required.

if you want to send the information to another page, you might wanna try using a session variable or even a cookie to store the information locally and you can retrieve it through code. Or....if you could just store the information in the database and retrieve it later. Or if you really wanna get tricky, you could write a decoding algorithm on the pin you produce.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 07-25-2008, 07:24 AM Re: Form on multiple pages???? Please help
Experienced Talker

Posts: 48
okay now my head really hurts
How would I create the router page and get it to work.
At the moment I've got three pages,
1) This has the form where the users adds their details
2) this is the page where the information from the previous page is sent, this is a remote url that has nothing to do the site
3) this is where the user enters the pin that they received after sending the form on the first page.
My goal is to have them on as fewer pages as possible. I don't mind if it's two pages, but before they can enter the pin the data from the first form needs to be sent to the remote address. Sorry to go over this again, but as I say I'm new to php and have never come across what you've mentioned so don't understand it. So far I've learnt to send information from a form to either an email address or a url, but nothing more complicated.
Thanks for help me.
thehappyappy is offline
Reply With Quote
View Public Profile
 
Old 07-25-2008, 01:43 PM Re: Form on multiple pages???? Please help
Super Talker

Posts: 122
OK page 1...the form

HTML Code:
<form action="router.php?id=1" method="POST">
form stuff
</form>
so all data from teh form gets posted to router.php?id=1
then the router page does all teh functions it needs to do before it outputs to the screen

then page 2...router page

HTML Code:
<html> // all php functions before the header!! if they aren't before the header, the whole $responseMessage / $header thing won't work.
<?php

switch($_GET['id'])
{
case 1:
create pin number, give pin number, store pin number...or w/e you need to do
You should save the pin number in a database linked to this persons ID
$responseMessage = "";
$header = "";
break;

default:
break;
} ?>
<head>
</head>
<body>
</body>
</html>
page 3....you just have them input the information and you cross check that with the database.

are you using a database? Are these users logged into the site?
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 07-28-2008, 07:07 AM Re: Form on multiple pages???? Please help
Experienced Talker

Posts: 48
Thanks for helping me with that. The users will be logged in and yes I am using a database
thehappyappy is offline
Reply With Quote
View Public Profile
 
Old 07-28-2008, 08:26 AM Re: Form on multiple pages???? Please help
upstarter's Avatar
Average Talker

Posts: 26
Name: Starr Horne
In some cases, you may not want to write any data to the DB until you get all of the input. If you're in that situation, you have a few options:

1) Use the same actual html page, but use JavaScript to give the impression that you're flipping pages. (My preference)

2) Use hidden form fields. When the user submits the first form, store those values in hidden fields on the second form, & so on.

Both of these options let you handle the final form submit, db query in a single action instead of splitting it up, which will result in cleaner code.
upstarter is offline
Reply With Quote
View Public Profile Visit upstarter's homepage!
 
Reply     « Reply to Form on multiple pages???? Please help
 

Thread Tools

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13999 seconds with 12 queries