0

Ill attempt to explain my issue - please bear with me.

I have 2 forms on a page, the fist form is populates the second form with address details but once called it loses all the details in it.

page1.php

<form action="anotherPage.php" id="database_submit" name="Form1">
<input type="text" name="Door Number" form="database_submit">
<input type="submit" value="Submit">
</form>


//when the below form is submitted it returns to this page
//and loses all data entered in the above form

<form action="page1.php" id="get_postcode" name="Form2">
<input type="text" name="getPostCode" form="get_postcode">
<input type="submit" value="Submit">
</form>

Is it possible to keep values entered in form1 when the user clicks form2, I have tried many things, but seem to have been unsuccessful (that's why I'm here). Hope you guys can help.

neophyte
  • 6,540
  • 2
  • 28
  • 43
Mark James
  • 481
  • 2
  • 6
  • 18
  • Possible duplicate of [PHP Pass variable to next page](http://stackoverflow.com/questions/871858/php-pass-variable-to-next-page) – mickmackusa Feb 26 '17 at 14:02

1 Answers1

0

No you have to populate the first form fields through your php..

Get the values using post method then pass them to the form fields..

Have some hidden fields in the next form..

<input type="text" name="Door Number" form="database_submit" 
style="display:none">
<input type="submit" value="Submit" style="display:none">

Pass the values from form 1 using javascript to form2 fields Submit the form using method=post

<form action="page1.php" id="get_postcode" name="Form2" method="post">

hen access them when the page1.php reloads after form submission--

<?php
$dn = !empty($_POST['Door Number']) ? $_POST['firstname'] : '';

 ?>
<input type="text" name="Door Number" form="database_submit" value="<?php 
 echo $dn;?>">

In this way you can achieve what you want..

hope this helps!

neophyte
  • 6,540
  • 2
  • 28
  • 43