首页 > 解决方案 > 方法帖子或会话

问题描述

我想将数据从表传递到字段表单这是 js 代码

<script type="text/javascript">
  var y = document.getElementById("num1").innerHTML;
  jQuery(document).ready(function($) {
        $(".coll").on("click", function() {
              window.location = '<?php echo site_url("inscription/"); ?>';
</script>

这是表格的一部分(formation.php)

<tr class='clickable-row'>
  <td id="num1" class="coll">
    <?php echo get_post_meta(get_the_ID(),'titre_module_'.$i,true); ?>
  </td>

  <td id="num2" class="coll">
    <?php echo get_post_meta(get_the_ID(),'desc_module_'.$i,true);  ?>
  </td>
  <td class="coll">
    <?php echo get_post_meta(get_the_ID(),'duree_'.$i,true);  ?>
  </td>
  <td class="coll">
    <?php $date_session =  wpautop(get_post_meta(get_the_ID(),'date_module_'.$i,true));
      echo $date_session;
     ?>
  </td>
  <td class="coll">
    <?php $date_session2 =  wpautop(get_post_meta(get_the_ID(),'sess2_'.$i,true));
      echo $date_session2;
     ?>
  </td>
</tr>

这是表单的字段(inscription.php)

<div class="form-group">
  <label title="Intitulé du module">Intitulé du module</label>
  <input type="text" name="intlmod" class="form-control" placeholder="Intitulé du module">
</div>

所以我希望当我点击一个 TD 时,它会将我重定向到该字段已满的表单页面

标签: phpjquerywordpress

解决方案


基本上,您可以使用 get 或 post 或 session 来完成,而不必使用 JS。这是使用 http get 方法和 urlencode 的示例格式。

<table>
<tr>
        <td id="num1"  class="coll"><a href="inscription.php?value=<?php echo urlencode(get_post_meta(get_the_ID(),'titre_module_'.$i,true)); ?>"><?php echo get_post_meta(get_the_ID(),'titre_module_'.$i,true); ?></a></td>

</tr>
</table>

在您的 inscription.php 页面中使用以下代码

       <div class="form-group">
<label title="Intitulé du module">Intitulé du module</label>
                <input type="text" name="intlmod" class="form-control" value="<?php echo $value = urldecode($_POST['value']); ?>" >

        </div>

推荐阅读