【问题标题】:Having Trouble Calling WordPress Plugin Form Value无法调用 WordPress 插件表单值
【发布时间】:2011-08-15 17:40:30
【问题描述】:

我的插件表单代码:

function pp_settings_page() {
    $pp_options = get_option('pp_options');
    ?>
    <div class="wrap">
        <h2>Post Products Settings</h2>
        <form action="options.php" method="post">
            <?php settings_fields('pp_options_group'); ?>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row">Currency sign: </th>
                    <td><input type="text" name="pp_options[currency_sign]" value="<?php echo $pp_options['currency_sign']; ?>" /></td>
                </tr>
            </table>
            <p class="submit">
                <input type="submit" class="button-primary" value="Save changes" />
            </p>
        </form>
    </div>
    <?php
}

我尝试在模板文件中调用它:

<?php $pp_options=get_option('pp_options');?>

<?php get_option('pp_options');?>

我错过了什么?

【问题讨论】:

    标签: php forms wordpress plugins


    【解决方案1】:

    我没有看到任何处理表单提交的代码,更具体地说,是提取 post 变量并使用 update_option 保存它的代码

    【讨论】:

      【解决方案2】:

      您的操作需要更改为设置页面 URL,以便在发布时运行下一段代码,您可以将其放入 pp_settings_page 函数中。

      if(isset($_POST['field_name'])) {
          $field_value = $_POST['field_name'];
          update_option('option_name', $field_value);
      }
      

      【讨论】:

        猜你喜欢
        • 2015-02-14
        • 2015-01-13
        • 2014-07-23
        • 1970-01-01
        • 2012-05-22
        • 1970-01-01
        • 2016-09-14
        • 2018-01-21
        • 2013-05-27
        相关资源
        最近更新 更多