如何将文本字段值传递给wordpress中的其他页面

时间:2018-06-13 07:48:22

标签: wordpress

我正在使用wordpress,我得到用户的位置数据,如邮政编码,我想知道我想在点击按钮时将此邮政编码发送到其他页面。这些是我的表单字段,我只想在其他页面上显示邮政编码。

 <div id="locationField">
<input id="autocomplete" type="text" placeholder="Enter your address" /></div>
<table id="address">
<tbody>
<tr style="display: none;">
<td class="label" style="display: none;">Street address</td>
<td class="slimField"><input id="street_number" class="field" style="display: none;" disabled="disabled" type="text" /></td>
<td class="wideField" colspan="2"><input id="route" class="field" style="display: none;" disabled="disabled" type="text" /></td>
</tr>
<tr style="display: none;">
<td class="label" style="display: none;">City</td>
<td class="wideField" colspan="3"><input id="locality" class="field" style="display: none;" disabled="disabled" type="text" /></td>
</tr>
<tr>
<td class="label" style="display: none;">State</td>
<td class="slimField"><input id="administrative_area_level_1" class="field" style="display: none;" disabled="disabled" type="text" /></td>
<td class="label">Zip code</td>
<td class="wideField"><input id="postal_code" class="field" disabled="disabled" type="text" /></td>
</tr>
<tr>
<td class="label" style="display: none;">Country</td>
<td class="wideField" colspan="3"><input id="country" class="field" style="display: none;" disabled="disabled" type="text" /></td>
</tr>
</tbody>
</table>
<input type="button" value="check" />

1 个答案:

答案 0 :(得分:0)

您可以通过多种方式将数据从一个页面传递到另一个页面。最简单和最基本的方法是form html元素。

出于此目的,我假设你有两个php页面或Wordpress模板,我们称之为start-page.phpfinish-page.php

启动page.php文件

<!-- If you are using wordpress the action would be
the url of the finish page, not the name of the php file -->
<form action="finish-page.php" method="POST">
  <!-- The name attribute below is important -->
  <input type="text" value="12345" name="postcode">
  <!-- Instead of input type submit, you can also use button type submit -->
  <input type="submit"/>
</form>

精page.php文件

<!--
    the name in quotes in square brackets matches
    the name attribute from the previous page -->
<?php echo $_POST['postcode'] ?>