PHP,是否可以在form2中使用form1,而action1不刷新form2

问题描述:

this is simple multi select form which select users and pass to input users

<form method="post" action="">
    <input name='input1' type='text'/>
    <input name='input2' type='text'/>
    <input name='input3' type='text'/>
    <select name="user[]" multiple="multiple" ondblclick="this.form.submit()">
        <option value="1">user1</option>
        <option value="2">user2</option>
        <option value="3">user3</option>
    </select>
    <input  type="text" name='selectedusers' value="<?php
      if (isset($_POST['user'])){
        $con = $_POST['user'];
        foreach($con as $user_single)
            echo '-'.$user_single; }
        ?> "/>
    <input type="Submit" value="abc" name="abc" />
</form>

now here the idea is to keep the input1, 2 and 3 which was input lastly, and make select. but here if i use multi select the previous input gets blank.

How i can keep the previous input values and make multi select pass the selected value to input name selectedusers and submit form..

regards

I dont think HTML standards allow nesting of forms. I had once ran into the same scenario and i saw this in http://www.w3.org/TR/html5/forms.html#the-form-element .

Content model: Flow content, but with no form element descendants.

i.e. html denies nesting of form elements. So, is it not possible to have form1 inside form2.

But you can use multiple submits inside the same form. and you can distinguish between the submits by the "name" and "value" attribute.

<form>
<input type="submit" name="submit" value="Submit 1" />
<input type="submit" name="submit" value="Submit 2" />

</form>

<?php

if(isset($_POST['submit']) and $_POST['submit']=="Submit 1")
{
...
}

if(isset($_POST['submit']) and $_POST['submit']=="Submit 2")
{
...
}

?>

What if you try with

extract($_POST);

in form submitted area.

and then assign values to form fields.

Let me know if its not clear.