【问题标题】:Create wordpress plugin that processes and submit form创建处理和提交表单的wordpress插件
【发布时间】:2016-02-29 21:46:07
【问题描述】:

我正在研究如何为 wordpress 制作插件,我可以制作一个插件,将简码添加到我的页面上并生成表单。

function mf_container($atts, $content = null) {
    $content = do_shortcode($content);
    $content = str_replace("<br />","",$content);
    $content = str_replace("<p>","",$content);
    $content = str_replace("</p>","",$content);
    return 
        "<form action='".plugin_dir_url( __FILE__ )."mult-form-submit.php' method='POST'>" . $content . "</form>";
}

add_shortcode('mult_form','mf_container');

现在精确地将此表单保存在与登录用户相关的银行中。

当我单击提交时,上面的代码将我重定向到“multi-form-submit.php”页面的方式。但是,当我进入该页面时,其中包含以下代码:

<?php if ( ! defined( 'ABSPATH' ) ) die("Not permited");

global $wpdb, $current_user;

$current_user = wp_get_current_user();

然而在worpress的情况下,她一直没有回来,任何人都可以做到吗?

【问题讨论】:

  • 如果请给出否定说明原因。所以我可以改进我的问题。谢谢。

标签: php wordpress forms


【解决方案1】:

我设法找到了一个有光的参考,并且经过多次尝试找到了如何做。那是参考:link

我使用的是WORDPRESS PLUGIN BOILERPLATE GENERATOR生成的插件结构

您应该在其中将在公共视图中开始的内容放在函数中:define_public_hooks()。在这个角色中,我进行了一次检查,启用了使用我的插件的选项:

/** Set build form by shorcodes*/
if($this->get_option('mult_form')){
   $this->loader->add_action('init', $plugin_public, 'mult_form');
}

本节将我重定向到控制我的所有公共行为的类的函数:

public function mult_form(){
    if(isset ( $_REQUEST['action']) and $_REQUEST['action'] == 'mult_form_submited'){
        $this->mult_form_submit();
    }
    $this->mult_form_shortcode();
}

称它为两个私有函数,在哪里做一些不会显示代码的处理,如果一切顺利,创建一个include_once('partials / my_file.php');,当然还有一个不同的文件,首先在哪里生成所有处理短代码和第二个我将放置所有治疗提交表格的位置。

【讨论】:

    猜你喜欢
    • 2018-01-04
    • 2012-05-22
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    相关资源
    最近更新 更多