Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation Pass Data from One Form to Another

    Hi, I'm pretty new to PHP; however, I'm faced with an annoying situation. Basically, I have a form on one page, that I would like the user to enter their information, click submit, and have it pass that information into a form on another page, and also submitting.

    For example, user enters first and last name in form one, clicks submit, and it passes the data to form two on another page, and also submits the form....possible?

    Thanks for any help or advice.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,519
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Yes ...

    Do the first form normally like ....

    <form action="second_form.php" method="post">
    blah blah
    </form>

    The next form, called "second_form.php" reads in all variables from the first form ...

    $name=$_POST['name'];
    $email=$_POST['email];

    Then, the next form has it's own variable, plus it has the previous one's as hidden ...

    <form action="process.php" method="post">
    <input type="hidden" name="name" value="<?=$name?>">
    <input type="hidden" name="email" value="<?=$email?>">

    <input type="text" name="age">
    </form>

    The script called "process.php" now reads them ALL in again.
    The same ones from the first form, plus the ones from the second form.

    $name=$_POST['name'];
    $email=$_POST['email];
    $age=$_POST['age'];


    The only problem you now have is when they go back,
    or skip to the second form, etc. You'll need to use PHP SESSION
    or cookies to remember both of the two form's variables.




    .
    Last edited by mlseim; 12-21-2010 at 03:18 PM.

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for the advice,

    the only thing is, they shouldn't need to go back. Let me explain. The first form will be on our site, it is actually a login form: i.e. Company, User, Pwd.

    I need it to pass this information into another form. So, when they click 'login' on our page, I wouldn't even need them to see the second form, just simply pass this information along, and login.

    Will this work?

  • #4
    New Coder
    Join Date
    Nov 2010
    Location
    United Kingdom
    Posts
    31
    Thanks
    0
    Thanked 9 Times in 8 Posts
    delete my post please
    Last edited by tropane; 12-21-2010 at 03:58 PM.

  • #5
    New Coder
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Why will I need to use three pages? Does the second one simply store the data?

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,519
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    A login should be a "login", nothing else.

    By passing username and password to another form, that will allow
    any user on that PC to view the HTML and see the username and password.

    For a login, you should direct that to a script by itself that
    sets a PHP SESSION. Then, that script can redirect to anywhere
    it wants, and the user is "logged-in".

    Typically, the username and password are compared on a database (MySQL?)
    and then if correct, a SESSION variable is set ... which could be the user ID
    or something to identify who is logged in.

    =============

    The answer to post #5 ... I have no idea what your site is about, or what the forms are,
    or if you use a database or not, or what the information is for ... basically, no idea.
    So, it's almost impossible to offer anything more than I did.


    .



    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •