[英]Submitting html form in php
這是我的first.php頁面html部分。 我有一個包括div和提交按鈕的表單。 我想要單擊按鈕時,打開一個新頁面(second.php)並顯示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>
這是javascript部分;
$("#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)
});
這是second.php,我要在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>
它不起作用,我應該更改什么?
如果$('#confirmForm')
不是輸入項,則無法使用$('#confirmForm').val()
;
您的表單缺少method
屬性,默認情況下在方法中添加POST
的GET
<form id="orderForm" method="post" action="second.php">
添加<textarea>
在first.php
內orderForm
持有的內容#ordelist
使用jQuery並在第二頁,你可以用它獲得$_POST['confirmForm']
;
<textarea name="confirmForm" id="confirmForm" cols="30" rows="10"></textarea>
在第二頁中,您可以執行此操作
<div id="confirmForm"> <?php echo $_POST['confirmForm'] ?> </div>
您正在嘗試將內容放入#confirmForm中,該內容在第一個文件中不存在。
這里不需要JavaScript。 使用$ _ ['post']獲取div的內容
試試這個它的工作:
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>
除了Saqueib所說的,我認為您也需要進行jQuery更改。 我認為您正在尋找html()方法,而不是val(),因為它看起來像您在嘗試更改顯示的HTML,對吧?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.