2018-02-05 03:41
浏览 32


I am developing a plugin where user will submit a form. The form submits to the same page. Form data handling code is implemented by checking the condition-

if ( !empty( $_POST['action'] ) && $_POST['action'] == 'customer_add_new')

Then the data is validated and entered to database using $wpdb->insert.

After that, I want to pass a variable to the URL, so that success message can be displayed and user can be stopped from re-submitting the form by refreshing the page. For that, I used-

$url = add_query_arg( array(
    'customer_add_new' => 'success'
    ) );
wp_redirect( $url );

But this code is throwing the following error-

Warning: Cannot modify header information - headers already sent by (output started at E:\wamp\www\cp_plugin\wp-includes\class.wp-scripts.php:343) in E:\wamp\www\cp_plugin\wp-includes\pluggable.php on line 1216

I have successfully used the same code in the theme for this very same project. But the functionality was better suited for a plugin, than for a theme.

图片转代码服务由CSDN问答提供 功能建议

我正在开发一个用户将提交表单的插件。 表单提交到同一页面。 表单数据处理代码通过检查条件 -

  if(!empty($ _POST ['action'])&& $ _POST ['action'] =来实现 ='customer_add_new')

然后使用$ wpdb-> insert验证数据并输入数据库。

之后,我想将一个变量传递给URL,这样就可以显示成功消息,并且可以通过刷新页面来停止用户重新提交表单。 为此,我使用了 -

  $ url = add_query_arg(array(
wp_redirect($ url);  

但此代码抛出以下错误 -

 警告:无法修改标题 信息 - 已在E:\ wamp \ www \ cp_plugin \ wp-includes \ pluggable.php中发送的输出(输出从E:\ wamp \ www \ cp_plugin \ wp-includes \ class.wp-scripts.php:343开始) 在第1216行

我已成功在主题中为同一个项目使用了相同的代码。 但是功能更适合插件而不是主题。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题