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 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址