简体   繁体   English

调用 WordPress 插件表单值时遇到问题

[英]Having Trouble Calling WordPress Plugin Form Value

My Plugin form code:我的插件表单代码:

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
}

I have tried to call it within the template files using:我尝试使用以下方法在模板文件中调用它:

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

and

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

What am I missing?我错过了什么?

I don't see any code to handle the form submit, more specifically, code which extracts the post variable and saves it using update_option我没有看到任何处理表单提交的代码,更具体地说,是提取 post 变量并使用update_option保存它的代码

Your action would need to be changed to the settings page URL so when it gets posted it runs the next bit of code, which you would put inside your pp_settings_page function.您的操作需要更改为设置页面 URL,因此当它发布时,它会运行下一段代码,您可以将其放入您的 pp_settings_page function 中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM