【问题标题】:Notice: Undefined index: recurring in /home/xxxxxx/public_html/wp-content/plugins/wordpress-stripe-integration/includes/settings.php on line 80 />注意:未定义索引:在第 80 行的 /home/xxxxxx/public_html/wp-content/plugins/wordpress-stripe-in​​tegration/includes/settings.php 中重复出现 />
【发布时间】:2017-04-08 12:08:21
【问题描述】:

我在使用 php api 库 v 4.2.0 设置条带插件时在后端收到此错误。 注意:未定义的索引:在第 80 行的 /home/public_html/wp-content/plugins/wordpress-stripe-in​​tegration/includes/settings.php 中重复 /> 选中此项以允许用户设置定期付款。

我的 settings.php 重复代码是

<table class="form-table">
            <tbody>
                <tr valign="top">   
                    <th scope="row" valign="top">
                        <?php _e('Allow Recurring', 'pippin_stripe'); ?>
                    </th>
                    <td>
                        <input id="stripe_settings[recurring]" name="stripe_settings[recurring]" type="checkbox" value="1" <?php checked($stripe_options['recurring'], 1); ?>/>
                        <label class="description" for="stripe_settings[recurring]"><?php _e('Check this to allow users to setup recurring payments.', 'pippin_stripe'); ?></label>
                    </td>
                </tr>
            </tbody>
</table>

我的 shortcode.php 代码是

<?php if(isset($stripe_options['recurring'])) { ?>
        <div class="form-row">
            <label><?php _e('Payment Type:', 'pippin_stripe'); ?></label>
            <input type="radio" name="recurring" value="no" checked="checked"/><span><?php _e('One time payment', 'pippin_stripe'); ?></span>
            <input type="radio" name="recurring" value="yes"/><span><?php _e('Recurring monthly payment', 'pippin_stripe'); ?></span>
        </div>
        <?php } ?>

单选按钮应该在结帐页面上可见,但不可见。我是 php 的初学者,所以任何帮助都会得到帮助。谢谢

【问题讨论】:

标签: php wordpress stripe-payments


【解决方案1】:

其实这不是错误,只是提示。它不会终止您的代码。您可能已经告诉服务器您想查看所有错误、警告和通知。

Offtopic:您可以使用以下命令禁用它们 错误报告(0); ini_set('display_errors', 0);

通知说明了一切——在数组变量 $stripe_options 中没有称为“重复”的索引。这个 settings.php 示例将删除通知。

<table class="form-table">
            <tbody>
                <tr valign="top">   
                    <th scope="row" valign="top">
                        <?php _e('Allow Recurring', 'pippin_stripe'); ?>
                    </th>
                    <td>
                        <input id="stripe_settings[recurring]" name="stripe_settings[recurring]" type="checkbox" value="1" <?php if(isset($stripe_options['recurring'])) { checked($stripe_options['recurring'], 1); } ?>/>
                        <label class="description" for="stripe_settings[recurring]"><?php _e('Check this to allow users to setup recurring payments.', 'pippin_stripe'); ?></label>
                    </td>
                </tr>
            </tbody>
</table>
        

无论如何,检查密钥是否使用 isset($array['key']) 设置是一个好习惯

【讨论】:

  • 感谢 Vachev,我现在通过检查并保存通知,发现通知已消失。
  • 当然,$stripe_settings[recurring] 只有在选中复选框时才会发送。只有在 settings.php 中设置了 $stripe_settings[recurring]。无论如何,首先检查 isset() 以确保您没有将 undefined 传递给您的函数 checked()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-05
  • 2018-09-27
  • 2017-05-06
  • 2019-10-01
  • 1970-01-01
  • 2014-01-12
  • 1970-01-01
相关资源
最近更新 更多