簡體   English   中英

如何使用PHP或任何其他方法獲取表單數據並將數據插入確切字段中的另一表單中

[英]How to fetch a form data and to insert the data into another form in the exact field using PHP or any other

在這里,我有表單1和表單2,具有相同的字段,如果單擊按鈕,表單2應該打開,其中表單1的數據已獲取。表單1的數據應准確放置在表單2中。(兩個表單都有相同的字段)任何幫助,將不勝感激。

>表格1的代碼

<table class="auto-style15" style="width: 100%; height: 100%">
<tr>
    <td class="auto-style21" style="width: 44px"><strong>Sl No</strong></td>
    <td class="auto-style21" style="width: 115px"><strong>Part No</strong></td>
    <td class="auto-style21" style="width: 88px"><strong>Part Rev</strong></td>
</tr>
<td class="auto-style7" style="width: 44px">
    <input name="Text157" style="width: 35px" type="text" /></td>
    <td class="auto-style7" style="width: 115px">
    <input name="Text20" style="width: 75px" type="text" /></td>
    <td class="auto-style7" style="width: 88px">
    <input name="Text232" style="width: 75px" type="text" /></td>
</td>
</table>

紐扣

<input id="cmaudit1" style="width: 90px" type="submit" value="Audit Checklist" 
    onClick="window.open ('form/CM form2.php',' width=500,height=400')"/>

表單2的代碼 ,當單擊按鈕時,表單1的數據應獲取並顯示到表單2的確切字段中

<table class="auto-style15" style="width: 100%; height: 50%">
    <input name="Text134" style="width: 130px; height: 38px;" type="text" /></td>
    <td class="auto-style21" style="width: 98px"><strong>Part</strong>
    <strong>NO</strong></td>
    <td class="auto-style7" style="width: 113px">

    <input name="Text129" style="width: 130px; height: 38px;" type="text" /></td>
    <td class="auto-style21" style="width: 59px"><strong>Rev</strong>
    <strong>No</strong></td>
    <td class="auto-style7" style="width: 101px">

    <input name="Text130" style="width: 130px; height: 38px;" type="text" />    </td>
    <td class="auto-style21" style="width: 60px"><strong>PO</strong> <strong>
    No</strong></td>
    <td class="auto-style7" style="width: 117px">
</td>
</table>

您可以將第一個窗體的方法設置為POST或GET,然后將其他窗體的字段的值設置為較舊的字段名稱。

<input type="text" name="fieldname_form_2" value="<?php echo $_POST['fieldname_form_1'] ?>">

您是否有“多個步驟”的表單? 如果有的話,有一些解決方案可能會有所幫助...

1:將先前發布的數據保存在會話或cookie中。 以后使用此數據。 會議將是更理想的解決方案。

表格1:

<form method="post" action="step2.php">
  <input type="text" name="your_name" placeholder="Your name">
  <input type="submit">
</form>

表格2(step2.php):

<?php $_SESSION['postData'] = $_POST; /* super simple example */ ?>
<form method="post" action="step3.php">
  <input type="text" name="your_address" placeholder="Your address">
  <input type="submit">
</form>

表格3(step3.php):

<?php $_SESSION['postData'] = array_merge($_SESSION['postData'], $_POST); /* super simple example */ ?>
<form method="post" action="finished.php">
  <input type="text" name="your_address" placeholder="Your address">
  <input type="submit">
</form>

然后,您可以稍后使用$_SESSION['postData']


2:將發布的數據回顯到隱藏的輸入字段中。 例:

表格1:

<form method="post" action="step2.php">
  <input type="text" name="your_name" placeholder="Your name">
  <input type="submit">
</form>

表格2(step2.php):

<form method="post" action="step3.php">
  <input type="hidden" name="your_name" value="<?php echo htmlentities($_POST['your_name']) ?>">
  <input type="text" name="your_address" placeholder="Your address">
  <input type="submit">
</form>

...等等...(請注意,這些表格並不全面,未經測試。僅用作示例。)

出現了太多的錯誤和一個簡單的問題。 Form2代碼中的表單標記在哪里? 也許您只想將值填入表格

<input name="Text157" style="width: 35px" type="text" />
<input name="Text20" style="width: 75px" type="text" />
<input name="Text232" style="width: 75px" type="text" />

在第二個表的正確單元格中。 在這種情況下,您需要使用javascript / jQuery函數,將HTML內容寫入表內,並帶有按鈕的onclick事件(按鈕在哪里?)

代碼太少,無法獲得更好的響應

使用$ _POST從表格1中獲取值: index.php

<html>
    <head>
        <meta charset="utf-8">
        <title>Index 1</title>
    </head>
    <body>
        <form action="index2.php" method="post">
            Part No<input type="text" name="PartNo" />
            <br />
            <input type="submit" name="btn" value="Send">
        </form>
    </body>
</html>

index2.php

<?php 
 $partNo=0;
if(!empty($_POST))
{
    $partNo=$_POST['PartNo'];
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Index 2</title>
    </head>
    <body>
        <form action="index2.php" method="post">
            Part No : <?php echo $partNo; ?>
        </form>
    </body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM