gpt4 book ai didi

wordpress - 使用 wordpress 插件的 HTML 表单操作?

转载 作者:行者123 更新时间:2023-12-05 07:48:48 25 4
gpt4 key购买 nike

函数 theme_options_panel(){ add_menu_page('ss title', 'Social Share', 'manage_options', 'theme-options', 'ss_callback');

   }
add_action('admin_menu', 'theme_options_panel');

函数 ss_callback(){

   $html .='<form action="index.php/wp-content/plugins/social_media/ss_query.php" method="post">';
$html .= '<br> <br>';
$html .= '<p class="description">';
$html .= 'Upload your social link here.';
$html .= '</p>';
$html .= 'Facebook:'.'<input type="URL" name="fb" value="" />';
$html .= '</br>';
$html .= 'Twitter:'.'<input type="URL" name="tw" value="" />';
$html .= '</br>';
$html .= 'Linkedin:' . '<input type="URL" name="lin" value="" />';
$html .= '</br>';
$html .= '<input type="submit" name="submit" value="Save">';
$html .= '</form>';

echo $html;


}

最佳答案

您不应将数据发送到插件中的 PHP 文件,否则您将无法在那里使用 WordPress 核心功能。

所以解决方案是使用钩子(Hook)。

在您的表单中放置一个隐藏字段,它应该是唯一的。例如:

<input type="hidden" name="unique_hidden_field" value="1">

你不再需要这个action,直接让它提交到当前页面即可:

<form action="" method="post">

PHP 代码:

add_action( 'init', 'process_post' );

function process_post() {
if( isset( $_POST['unique_hidden_field'] ) ) {
//You code goes here
//You can use $_POST['fb']
}
}

希望对您有所帮助!

关于wordpress - 使用 wordpress 插件的 HTML 表单操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38179327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com