drra6593 2016-02-20 17:54
浏览 37
已采纳

Wordpress表格处理

I have created a form on my wordpress site, a function to process the data located in functions.php, and an action php file. I have tested the processing function and know it works, but I'm having trouble getting everything to communicate with wordpress.

update_item_meta.php is located in my theme directory.

Form Opening Tag

<form method="post" id="project-info" action="/wp-content/themes/Avada/update_item_meta.php">

update_item_meta.php

<?php
//connect to WP
define('WP_USE_THEMES', false);
require('../../../wp-load.php');

//call function from functions.php to process form data
update_item_meta_data();
?>

Note: wp-load.php is located in the main site root

If someone could help me out I would really appreciate it. If i had to guess it's a problem with either the path to update_item_meta.php in the form action or update_item_meta.php, but I haven't been able to figure it out.

  • 写回答

1条回答 默认 最新

  • duanjuan1103 2016-02-20 19:46
    关注

    action="/wp-content/themes/Avada/update_item_meta.php"

    You will obviously not load wp calling a php file directly and using relative paths to load wp is problematic.

    The best way to deal with forms in wp are to post to the same url:

    1. action="#" with a hidden input for a unique field to identify your form and in your functions file a function to pick up the post action....

      if($_POST['unique']){
        require_once 'yourfile.php';
        //or your form process code here
      }
      
    2. action="#" and place code to handle the post in your template file (not the wp way but helps prevent a load of code from being loaded that is not relevant to the page.

    Both ways will have wp loaded for you without having to manually load.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么