0

This is my first.php page html part. I have a form including a div and a submit button. I want when button clicked, open a new page (second.php) and display contents of div(id=orderList)

<form id="orderForm" action="second.php">
 <div class="col-md-5" id="orderList">
 <h3 align="center">Sipariş Listesi</h3>
 </div> 
 <div>
 <button type="submit" id="firstConfirmButton" class="btn btn-primary btn-lg">Onayla</button>
 </div>
</form>

This is javascript part;

 $("#orderForm").submit(function() {
 var content = $('#orderList').html();
 console.log(content); //(no problem everything is ok)
 $('#confirmForm').val(content);
 var content2 = $('#confirmForm').html();
 console.log(content2); //(it is null)
}); 

And this is second.php where I want to display the contents in the div(id=confirmForm)

<html>
 <head> 
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
 <script type="text/javascript" src="script.js"></script>
 <META name=viewport content="width=1024, initial-scale=1">
 <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <META HTTP-EQUIV="Content-language" CONTENT="tr">
 <link href="shift.css" rel="stylesheet"> 
 <link rel="stylesheet" href="bootstrap.css">
 <link rel="stylesheet" href="product.css">
 </head>
 <body>
 <div id="confirmForm"> </div> 
 </body>
</html>

It doesn't work, what should I change?

asked Nov 1, 2014 at 12:19
1
  • Google ajax with jquery if you want the contents of the second page to be displayed on the current page you are submitting the form using an asynchronous request. Commented Nov 1, 2014 at 12:21

4 Answers 4

2

If $('#confirmForm') is not an input item you cant access it using $('#confirmForm').val();

your Form is missing method attribute, add POST in method by default its GET

<form id="orderForm" method="post" action="second.php">

Add a <textarea> in first.php inside orderForm to hold the content of #ordelist using jquery and in second page you can get it using $_POST['confirmForm'];

<textarea name="confirmForm" id="confirmForm" cols="30" rows="10"></textarea>

in second page you do this

<div id="confirmForm"> <?php echo $_POST['confirmForm'] ?> </div> 
answered Nov 1, 2014 at 12:33
Sign up to request clarification or add additional context in comments.

5 Comments

I can see the text area filled with content, no problem thnks for solution. But second.php is blank? var_dump($_POST['confirmForm']); is null
just use print_r($_POST); on top of second page to see what it gives you. you must get the content from form submission, and then use key as i shown you above
print_r($_POST); result is Array ( )
updated form method to post <form id="orderForm" method="post" action="second.php"> that will do it
yepp, it is solved. Thanks, I forgot to put textarea in orderForm.
0

You're trying to put the content in #confirmForm, which isn't present in the first file.

There is no need for JavaScript here. Grab the content of the div using $_['post']

answered Nov 1, 2014 at 12:36

2 Comments

How should I use $_['post'], in first.php or second.php?
I changed it but still null
0

Try this its working :

first.php

<html>
<head>
</head>
<form id="orderForm" action="second.php">
 <div class="col-md-5" id="orderList">
 <textarea name="confirmForm" id="confirmForm" cols="30" rows="10">Sipari Listesi</textarea>
 </div> 
 <div>
 <button type="submit" id="firstConfirmButton" class="btn btn-primary btn-lg">Onayla</button>
 </div>
</form>
</html>

second.php

<html>
 <body>
<?php 
 echo $_REQUEST[confirmForm];
?>
 </body>
</html>
answered Nov 1, 2014 at 12:59

Comments

0

In addition to what Saqueib said, I think you'll need to make a jQuery change too. I think you're looking for the html() method, not val() because it looks like you're trying to change the displayed HTML, right?

answered Nov 1, 2014 at 18:49

1 Comment

I tried that but it denied me twice. Wasn't sure why though.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.