user3643404
user3643404

Reputation: 33

How to submit two php forms to one location

I have two php forms, both for registration means (enter name, username, password etc). My first registration form (reg1.php) contains the basic inputs as I mentioned above and then I have a second registration form (reg2.php) that includes checkboxes where the form would ask the user other questions before finalizing their sign up.

What I am having trouble with is that when I enter data into my inputs in the first registration form, then proceed to the next registration page and fill that out and click Sign Up, my output on my server only obtains the information I inputted in the second registration page, not the first.

How can I get both inputted data from the two registration pages to appear together? I have been told about POSTBACK to help with this but I am not all that familiar with how to use it.

First php page:

<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table style="width:300px">
<form name="Rego" method="post" action="rego2.php">
<tr>
<td><label>Name:</label></td>
<td><input type="text" name="fname"/></td>
</tr>
<tr>
<td><label>Username:</label></td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td><label>Password:</label></td>
<td><input type="password" name="password" id="pass" /></td>
</tr>
<tr>
<td><label>Confirm Password:</label></td>
<td><input type="password" name="conpassword" id="conpass"/></td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Next Page">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>

Second php page

<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table>
<form name="Rego" method="post" action="http://myserver...">
<tr>
<td>
<input type="checkbox" name="checkbox" value="Agree to T&C">I agree to the <a href="tnc.php">Terms and Conditions</a><br> 
<input type="checkbox" name="checkbox" value="No Criminal Records">I have no criminal associations<br>
</td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Sign Up">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>

Upvotes: 1

Views: 94

Answers (3)

Bipul Khan
Bipul Khan

Reputation: 707

In 2nd input form you take first inout from value and keep those one as hidden.

and 2nd input form you should

<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table>
<form name="Rego" method="post" action="http://myserver...">

<input type="hidden" name="fname" value="<?php echo  $_POST['fname'];?> " />
<input type="hidden" name="username" value="<?php echo  $_POST['username'];?> " />
<input type="hidden" name="passowrd" value="<?php echo  $_POST['password'];?> " />
<input type="hidden" name="conpassowrd" value="<?php echo  $_POST['conpassword'];?> " />
<tr>
<td>
<input type="checkbox" name="checkbox" value="Agree to T&C">I agree to the <a href="tnc.php">Terms and Conditions</a><br> 
<input type="checkbox" name="checkbox" value="No Criminal Records">I have no criminal associations<br>
</td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Sign Up">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>

I hope it will work for you.

Upvotes: 1

user3030212
user3030212

Reputation: 439

In the second page, you can get the post data from page 1 and set it in a hidden field like this, say the fname:

<input type="hidden" name="fname" id="fname" value="<?php echo $_POST['fname'] ?>">

When you submit from the second page, you can catch this data in the destination page, say

$_POST['fname']

Upvotes: 0

user1864610
user1864610

Reputation:

When the first form is submitted either store the data in a $_SESSION variable and retrieve it when you process the second form, or write it to hidden <input> elements on your second form and retrieve it from the $_GET or $_POST array

Upvotes: 2

Related Questions