简体   繁体   English

从第一页获取按钮的值,并将其回显到“模态”和第二页

[英]Getting the value of the button from the 1st page and echoing it to the Modal and to the 2nd page

I know some of you this problem is pretty simple to do, but I am working in a week to find it out what are the right codes to function it well. 我知道你们中的某些人很容易解决这个问题,但是我花了一周的时间来找出解决该问题的正确代码。

in the 1stpage.php there is a multiple buttons with different values in it 在1stpage.php中,有多个具有不同值的按钮

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#myModal" data-toggle="modal" value="#01" name="btn" class="button2 btn btn-primary model_open" data-btnval = "#01" aria-hidden="true" data-dismiss="modal" >form</a>

<a href="#myModal" data-toggle="modal" value="#02" name="btn" class="button2 btn btn-success model_open" data-btnval = "#02" aria-hidden="true" data-dismiss="modal" >form</a>

<a href="#myModal" data-toggle="modal" value="#03" name="btn" class="button2 btn btn-warning model_open" data-btnval = "#03" aria-hidden="true" data-dismiss="modal" >form</a>

在此处输入图片说明

that can open the Modal Form inside the page 可以在页面内打开模态表格

  $(document).on("click", ".model_open", function () {
    var btnval = $(this).data('btnval'); 
   $(".modal-body #btnval").text( btnval );
$('#hiddenid').val(btnval ); 
});e here

on the Modal Form you'll see the current value button echoed on the form, because of the script and this code 在模态表单上,您将看到当前值按钮在表单上回显,这是因为脚本和此代码

<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" 
tabindex="-1" id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header1" style="padding:10px 15px;">
         <button type="button" class="close" data-dismiss="modal" >&times;
         </button>
    <h4><span class="glyphicon glyphicon-pencil"></span> FORM</h4>
</div>
<div class="modal-body" style="padding:10px 10px;">

<h6 class="sub-heading-2 tiny text-medium text-center-xs">

<?php
    $divName="btnval";
    echo "<div id=$divName></div>"; <!-- echoing the button value -->
?>
 <div class="modal-body">

<form action="2ndpage.php" method="get" enctype="multipart/form-data">

<div class="col-sm-6">
  <div class="form-group">
    <label for="lname">Name</label>
      <input type="text" class="form-control" name="lname" id="lname" 
      required="required" placeholder="Name">
  </div>
</div>

<input type="submit" id="btn-next" class="btn btn-success pull-right" 
 value="NEXT"> 
</form>

on the Modal form there is NEXT button which will you proceed to the 2ndpage.php to see and double check the information you provided on the form, together with the Value Button you've clicked from the first page. 在“模态”表单上,有一个“下一步”按钮,您将进入2ndpage.php以查看并仔细检查您在表单上提供的信息,以及从第一页单击的“值”按钮。

在此处输入图片说明

 <div class="label-field-pair">
<label>Name</label>
<input class="form-control" id='name' name='name' value='<?php echo 
$_GET["name"]; ?>'  />
</div>

<div class="label-field-pair">
<label>ID</label>
<input class="form-control" id='id' name='id' value='<?php echo 
$_GET["btnval"]; ?>'  />
</div>

It seems pretty simple but I can't find a good way to do it. 看起来很简单,但是我找不到很好的方法。 I was tried a much code with the codes from the others to get the name value of the current button to be echo on the 2ndpage.php, but I always got an error. 我尝试了很多其他代码,以获取当前按钮的名称值以在2ndpage.php上回显,但是我总是遇到错误。

SOLVED: 1stpage.php 解决了:1stpage.php

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Buttons start 按钮启动

<a href="#myModal" data-toggle="modal" value="#01" name="btn" class="button2 btn btn-primary model_open" data-btnval = "#01" aria-hidden="true" data-dismiss="modal" >form</a>
<a href="#myModal" data-toggle="modal" value="#02" name="btn" class="button2 btn btn-success model_open" data-btnval = "#02" aria-hidden="true" data-dismiss="modal" >form</a>
<a href="#myModal" data-toggle="modal" value="#03" name="btn" class="button2 btn btn-warning model_open" data-btnval = "#03" aria-hidden="true" data-dismiss="modal" >form</a>

Getting the current button id by using this script 使用此脚本获取当前按钮ID

$(document).on("click", ".model_open", function () {
            var btnval = $(this).data('btnval'); 
           $(".modal-body #btnval").text( btnval );
        $('#hiddenid').val(btnval); 
        });

Modal Form 模态形式

<div class="modal-body">
<form action="2ndpage.php" method="get" enctype="multipart/form-data">
<h6>
    <?php
            $divName = "btnval";
                echo '<div id="'.$divName.'"></div>';
    ?>
</h6>
<input type="hidden" name="id" value="<?php echo $divName; ?>">
<input type="hidden" id="hiddenid" name="btnval">
<div class="form-group">
    <input type="text" class="form-control" name="name" id="name"         
    required="required" placeholder="Name">
</div>
<input type="submit" class="btn btn-success" value="NEXT"></form></div>

2ndpage.php 2ndpage.php

<label>ID</label>
  <input class="form-control" id='id' name='id' value='<?php echo 
     $_GET["btnval"]; ?>'/>
</div>
 <div class="label-field-pair">
<label>NAME</label>
  <input class="form-control" id='name' name='name' value='<?php echo 
     $_GET["name"]; ?>' />
</div>

尝试将值保存在cookie中,然后在第二页上调用该cookie。

How about you send a hidden value?? 您如何发送隐藏值?

Trigger: 触发:

  <a data-toggle="modal" data-id="#03" title="Add this item" class="button2 btn btn-warning model_open" href="#myModal">test</a>

Modal: 模态:

<form action="2ndpage.php" method="get" enctype="multipart/form-data">

 <div class="col-sm-6">
  <div class="form-group">
   <label for="lname">Name</label>
    <input type="text" class="form-control" name="lname" id="lname" 
    required="required" placeholder="Name">
  </div>
  <input type="hidden" name="whatyouwant" id="whatyouwant" value=""/>
 </div>

 <input type="submit" id="btn-next" class="btn btn-success pull-right" value="NEXT"> 
</form>

jquery: jQuery的:

 $(document).on("click", ".model_open", function () {
    var btnval = $(this).data('id');
    $(".modal-body #whatyouwant").val(btnval);
 });

On 2ndpage.php: 在2ndpage.php上:

  1. Echo Value 回声值

     <?php echo "<pre>"; print_r($_REQUEST); echo "</pre>"; ?> 
  2. Output. 输出。

     Array ( [lname] => sdsa [whatyouwant] => #03 ) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM