使用来自另一个表单的数据填充表单


Populate form with data from another form

>我有一个小游览的页面,在游览点内是输入。此页面上还有另一种表单,这些表单具有相似的输入,包括名字、姓氏等......

如果用户在表单

1 中输入他们的名字,如何填充表单 2 的名字字段?

这是表格 1:

<form role="form" id="inviteform3" class="form-inline" action="name.php" method="POST">
<div class="form-group">
<input type="text" class="form-control input-sm" name="name" placeholder="First Name" 
id="hello" autocomplete="off" style="margin-top:10px">
                            </div>
                            <center>
                            <span id="start">Let's get started, <span id="result"></span></span>

                            <button class="btn btn-brand btn-sm next-screen animated bounceInUp" 
id="go" style="margin-top:5px; display:none" href="#services" data-animation-delay=".5s"> 
Let's Go!</button></center>
    <button class="btn btn-block btn-brand btn-xs invitebtn3" id="casi" type="submit" 
style="margin-top:5px"><i class="fa fa-thumbs-o-up"></i> Submit</button>
</form>

这是表格 2:

<form role="form" id="inviteform" class="form-inline" 
action="http://omnihustle.net/demo/invitations/invite_request" type="POST"><div 
class="form-group">
<input type="text" class="form-control input-sm" id="InputFirstName" placeholder="First 
Name">
                            </div>
    <div class="form-group">
<input type="text" class="form-control input-sm" id="InputLastName" placeholder="Last 
Name">
                            </div>
<div class="form-group">
<input type="email" class="form-control input-sm" id="InputEmail" placeholder="Email">
  </div>
<button class="btn btn-brand btn-sm invitebtn" type="submit" data-toggle="modal" data-
target=".bs-example-modal-sm"><i class="fa fa-check fa-fw"></i> Invite Me</button></form>

这是我的 php 文件,表单被发送到:

<html>
<body>
<?php session_start(); ?>
<?php
 if  (isset($_POST['name']) && !empty($_POST['name'])) {
    $_SESSION['name'] = $_POST['name'];
 }
?>
<?php echo $_POST["name"]; ?>
</body>
</html>

Jquery 不起作用,因为我无法在表单的"值"字段中输入 html,那么有什么替代方案呢?

这是我尝试过的;

<script>
$(document).on("ready", function(){
//Form action
$("#inviteform3").on("submit", function(event){
// Stop submit event
event.preventDefault();
$.ajax({
    type:'POST', 
    url: 'name.php',
    data:$('#inviteform3').serialize(), 
    success: function(response)  
    {
        $('#inviteform3').find('#result').html(response);
        $('.coupontooltip5').find('#result2').html(response);
        $('#announcement').find('#result3').html(response);
        $('#announcement2').find('#result4').html(response);
        $('#progressbutton').find('#result5').html(response);
        $('#inviteform').find('#result6').html(response);

    }});
});
});
</script>

我尝试将"span id="result6"输入到输入的"value"标签中,表单不允许该功能,只是将html显示为输入的默认值。

您可以添加一个将内容复制到第二个字段的"keyup"处理程序。将以下行添加到"就绪"处理程序中。

$('#hello').on('keyup', function() {
  $('#InputFirstName').val($(this).val());
});

如果添加"更改"处理程序而不是此"keyup"处理程序,则仅在字段失去焦点后调用该处理程序。

顺便说一下,name.php不起作用。 在进行任何输出之前,必须调用 session_start()。因此:

<?php session_start(); ?>
<html>
<body>