0

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

<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>

enter image description here

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.

enter image description here

 <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.

SOLVED: 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

$(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

<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>
Marvin Acosta
  • 168
  • 10

2 Answers2

0

Try to save the value in a cookie and call the cookie on the second page.

pradeep kumar
  • 983
  • 10
  • 21
  • hello @pradeep thank you for your time. do you have a code for that? I'll never try that way, I have no idea to do that??? can you show me your code? thank you – Marvin Acosta Nov 09 '17 at 00:56
  • Hi mate! Please refer this link: https://stackoverflow.com/questions/20877142/how-to-save-data-in-a-cookie-using-jquery – pradeep kumar Nov 09 '17 at 09:05
  • Hi, @pradeep thank you for the link. but seems is too much confusion. is that the only way to function well my problem? or there is any right and easy way on how could I put name inside the 'div id' to get and echo its value to another page like the normal way of value='' /> – Marvin Acosta Nov 10 '17 at 01:20
0

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:

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

On 2ndpage.php:

  1. Echo Value

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

    Array
    (
       [lname] => sdsa
       [whatyouwant] => #03
    )
    
Salehin Rafi
  • 351
  • 2
  • 6
  • 16
  • hello @Salehin thank you for the response. I'll try your code now. ^^ – Marvin Acosta Nov 16 '17 at 00:29
  • Hi, @Salehin your code is ok, but the button value is not echoed in the right value itself, which is supposedly the "#01" or which button should I clicked. it echoed only the "btnval" that I used in – Marvin Acosta Nov 16 '17 at 00:56
  • and here is the code to 2ndpage.php – Marvin Acosta Nov 16 '17 at 00:58
  • @MarvinAcosta I made a slight change to the code above. Also, the code above running on my localhost. – Salehin Rafi Nov 16 '17 at 06:57
  • hello, @Salehin thank you for the time and effort but my problem is already done ^___^ – Marvin Acosta Nov 16 '17 at 07:56
  • @MarvinAcosta No problem. BTW can you post your solution and closed this question. Thank you. – Salehin Rafi Nov 16 '17 at 10:00
  • I can't delete my question because you and the others have the effort to help me out regarding on this matter. I only re-edit my post to the right code. – Marvin Acosta Nov 17 '17 at 01:46
  • No. I didn't mean for you to delete the post. What I mean you closed the question by answering your own question, so that others will not try to solve it. After your post your answer. you need to accept the answer. Read more here: https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work . – Salehin Rafi Nov 17 '17 at 02:35
  • I tried to, but the system is no longer accepting my answer on this account :( – Marvin Acosta Nov 17 '17 at 02:52
  • I was updated my post and put the right solution next to the problem. ^__^ – Marvin Acosta Nov 17 '17 at 02:58