dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Populate form from the form of previous page?

  1. #1
    Join Date
    Oct 2004
    Posts
    25

    Populate form from the form of previous page?

    Hi,

    I am trying to figure out how to implement the following:

    on the first page, I have a form naed form1 and two fields: name and phone.
    <form name="form1" action="nextPage.php" method="post">
    <table>
    <tr>
    <td> Name:<input id="name" size="10" name="name"></td>
    <td> Phone:<input id="name" size="10" name="phone"></td>
    </tr>
    <tr>
    <td><input type="button" value="Submit" name="Submit"></td>
    </tr>
    </table>

    on the second page, I have another form but with more fields:
    <form name="form2" action="nextPage.php" method="post">
    <table>
    <tr>
    <td> Name:<input id="name" size="10" name="name"></td>
    <td> Phone:<input id="phone" size="10" name="phone"></td>
    <td> Zip Code:<input id="zipcode" size="5" name="zipcode"></td>
    <td> Address:<input id="address" size="30" name="address"></td>
    </tr>
    <tr>
    <td><input type="button" value="Submit" name="Submit2"></td>
    </tr>
    </table>

    What I am trying to do is: user fills in name/phone on the first page, hits
    submit button, she goes to the second page. On the second page, I want to have name/phone fields automatically filled with previous values from first page.

    How can I do that?

    thanks,

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    If these are php pages, and I assume they are because you have title the action in your form nextPage.php, you can just use the code as follows for your second page

    <form name="form2" action="nextPage.php" method="post">
    <table>
    <tr>
    <td> Name:<input id="name" size="10" name="name" value="<?php echo $_POST['name']; ?>"></td>
    <td> Phone:<input id="phone" size="10" name="phone" value="<?php echo $_POST['phone']; ?>"></td>
    <td> Zip Code:<input id="zipcode" size="5" name="zipcode"></td>
    <td> Address:<input id="address" size="30" name="address"></td>
    </tr>
    <tr>
    <td><input type="button" value="Submit" name="Submit2"></td>
    </tr>
    </table>

    And to give you some information about php.....

    The information you submit through a form using the get method is available through the variables

    $_GET['name_of_field']

    and the information you submit through a form using the post method is available through the variables

    $_POST['name_of_field']

    Hope that helps

  3. #3
    Join Date
    Oct 2004
    Posts
    25
    Thank you very much, that does the trick.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles