想在我完成button_submit时加载另一个 PHP 文件


Wanna load another php file when im done with button_submit

<?php function my_plugin_settings_page() {?>
    <div class="wrap">
    <h2>Staff Details</h2>
    <form method="post" action="options.php">
    <?php settings_fields( 'my-plugin-settings-group' ); ?>
    <?php do_settings_sections( 'my-plugin-settings-group' ); ?>
    <table class="form-table">
        <tr valign="top">
        <th scope="row">Accountant Name</th>
        <td><input type="text" name="accountant_name" value="<?php echo esc_attr( get_option('accountant_name') ); ?>" /></td>
        </tr>
        <tr valign="top">
        <th scope="row">Accountant Phone Number</th>
        <td><input type="text" name="accountant_phone" value="<?php echo esc_attr( get_option('accountant_phone') ); ?>" /></td>
        </tr>
    </table>
    <?php submit_button( 'Save Settings', 'primary', 'wpdocs-save-settings' ); 
    if (isset($_GET['submit'])) {
        header('Location: wamp'www'wordpress'wordpress'wp-content'plugins'MaximoPlugin'andra.php');
        exit;
    }?>
    </form>
    </div>

我的问题是,我可以通过向button_submit添加操作将用户重定向到 wordpress 中的另一个 php 文件吗?

所以它有两个事件。保存用户,然后将用户重定向到另一个页面。

在路上可能吗?顺便说一句,我是PHP和WordPress的新手,所以我很抱歉糟糕的代码和东西。

if语句我发送了我知道的任何好处,但是我如何检查按钮是否已提交,然后将用户重定向到另一个WordPress页面。(另一个 PHP 站点。

请给我一些关于我可以做什么或应该做什么的意见。

编辑:

好的,我将其更改为包含,但没有得到任何响应。

        </table>
    <?php submit_button(); 
    if(isset($_POST['submit']))
    {
    include('andra.php');
    }
    }?>
您可以使用

wp_redirect http://codex.wordpress.org/Function_Reference/wp_redirect 将用户重定向到另一个 URL。只需在重定向呼叫之前保存您的数据即可。

<?php
wp_redirect( $location, $status );
exit;
?>

问题不是很清楚,所以我将展示两种解决方案,您可以选择更适合您的一种:

解决方案 1:

handle_my_request.php制作另一个文件

更改代码中的以下行:

<?php submit_button( 'Save Settings', 'primary', 'wpdocs-save-settings' ); 
    if (isset($_GET['submit'])) {
        include_once("handle_my_request.php");
        exit;
    }?>

现在在 handle_my_request.php 中,您可以轻松编写处理请求的方式。例如。

<?php
$var1 = $_GET['myvar1'];
do_something($var1);
?>

解决方案 2:

您需要手动制作另一个表单并将字段发布到所需的其他页面。为此,您可以通过PHP在服务器端进行GET/POST(使用CURL),也可以通过客户端的javascript进行GET/POST。

<?php function my_plugin_settings_page() {?>
<div class="wrap">
<h2>Staff Details</h2>
<form method="post" action="options.php">
<?php settings_fields( 'my-plugin-settings-group' ); ?>
<?php do_settings_sections( 'my-plugin-settings-group' ); ?>
<table class="form-table">
    <tr valign="top">
    <th scope="row">Accountant Name</th>
    <td><input type="text" name="accountant_name" value="<?php echo esc_attr( get_option('accountant_name') ); ?>" /></td>
    </tr>
    <tr valign="top">
    <th scope="row">Accountant Phone Number</th>
    <td><input type="text" name="accountant_phone" value="<?php echo esc_attr( get_option('accountant_phone') ); ?>" /></td>
    </tr>
</table>
</form>
<?php 
    submit_button( 'Save Settings', 'primary', 'wpdocs-save-settings' ); 
    if (isset($_GET['submit'])) 
    { ?>
    <form name="redirection_form" action="http://anotherwebsite.com" method="post">
        <input type="hidden" name="accountant_name" value="<?php echo esc_attr( get_option('accountant_name') ); ?>" />
        <input type="hidden" name="accountant_phone" value="<?php echo esc_attr( get_option('accountant_phone') ); ?>" />
    </form>
    <script type="text/javascript">
        document.redirection_form.submit();
    </script>
<?php } ?>
</div>

不用说,您需要更改表单的变量、方法和操作,以匹配您要重定向到的下一页。

正如我之前所说,PHP CURL也可以实现同样的目的。

        <form method="post" action="options.php">
    <input type='hidden' name='option_page' value='my-plugin-settings-group'   /><input type="hidden" name="action" value="update" /><input type="hidden" id="_wpnonce" name="_wpnonce" value="fc1447e3e7" /><input type="hidden" name="_wp_http_referer" value="/wordpress/wordpress/wp-admin/admin.php?page=my-plugin-settings&amp;settings-updated=true" />              <table class="form-table">
        <tr valign="top">
        <th scope="row">Accountant Name</th>
        <td><input type="text" name="accountant_name" value="1" /></td>
        </tr>
        <tr valign="top">
        <th scope="row">Accountant Phone Number</th>
        <td><input type="text" name="accountant_phone" value="1" /></td>
        </tr>
    </table>
    <p class="submit"><input type="submit" name="wpdocs-save-settings" id="wpdocs-save-settings" class="button button-primary" value="Save Settings"  /></p>

这是源视图。是的,andra.php 在同一个目录中。

我正在为 Wordpress 制作一个插件,它与此有关吗?