-3
<form id = "msform" action = "" method = "POST">
<input type = "text" name = "name" />
<input type = "submit" name = "submit1" value "Submit" />
</form>
<form id = "msform" action = "" method = "POST">
<b>Name:</b> <?php echo $_POST['name']; ?> 
<input type = "submit" name = "submit2" value "Launch" />
</form>

I am using two HTML forms, I want to display one form's data to other any one can guide me that how it is possible??

Hamood
  • 1
  • 1
  • 1
  • 3

4 Answers4

1

Try this, check which button is submitted.

if ($_SERVER["REQUEST_METHOD"] == "POST") 
{
    if ($_POST['submit1'] == 'Submit') {
      // Submit button 
    }
    else 
    {
      // Launch button 
    }
}
Dave
  • 3,073
  • 7
  • 20
  • 33
  • 1
    I prefer this type of checking on which button is clicked. Safe, simple and clean. Recommended also for starters. – Irvin Nov 08 '16 at 07:59
  • var form1 = document.getElementById("msform"); form1.onsubmit = function(){ document.getElementById("msform2").style.display = "block"; }; i was done it like this but 2nd form is not show i think its animation problem of jquery – Hamood Nov 09 '16 at 05:32
0

works fine for me. but a button is a <button> and not a input type submit. and never touch global vars like $_POST and $_GET directly, use filter_input for that. the other thing is, an id is only for use 1 time, you used the same id for both forms.

<form id="msform1" action="" method="POST">
    <div>
        <input type="text" name="name" />
    </div>
    <button type="submit" name="submit1">
        Submit
    </button>
</form>

<form id="msform2" action="" method="POST">
    <div>
        <b>Name:</b> <?php echo filter_input(INPUT_POST, 'name'); ?> 
    </div>
    <div>
        <button type="submit" name="submit2">
            Launch
        </button>
    </div>
</form>
mtizziani
  • 956
  • 10
  • 23
0

I think you are using two from in one html page and want to display one form's field value to another on button click. In this case it will be better to use js/jquery. you can easily get one filed value and put into another filed with js/jquery.

//Get
var val = $('#field_id').val();

//Set
$('#field_id').val('bla'); 
Dave
  • 3,073
  • 7
  • 20
  • 33
  • But in my case there are many fields if i will do this it will becomes too much lengthy code – Hamood Nov 09 '16 at 05:36
0
var form1 = document.getElementById("msform");
 form1.onsubmit = function(){
 document.getElementById("msform2").style.display = "block"; 
}; 

i was done it like this but 2nd form is not show on submit button click i think its animation problem of jquery

Hamood
  • 1
  • 1
  • 1
  • 3