在WordPress插件中使用zebra_form时出错


error using zebra_form in a wordpress plugin

我正在尝试在元框中使用Zebra_form,用于我正在处理的Wordpress插件。

简单起见,我将代码简化为:

public function render_metabox( $post ) {
    // instantiate a Zebra_Form object
    $form = new Zebra_Form('form');
    // the label for the "email" field
    $form->add('label', 'label_email', 'email', 'Email');
    // add the "email" field
    $obj = $form->add('text', 'email', '', array('autocomplete' => 'off'));
    // auto generate output, labels above form elements
    $form->render();
}

但是当我尝试运行它时,我收到以下错误:

Warning: Cannot modify header information - headers already sent by (output started at /Users/dp/Documents/SitesDev/wordpress/wp-admin/includes/template.php:1877) in /Users/dp/Documents/SitesDev/wordpress/wp-content/plugins/my-plugin/lib/Zebra/Zebra_Form.php on line 4052

Fatal error: The library tried to store the CSRF token in a cookie but was unable to do so because there was output already sent to the browser. You should either start a session prior to instantiating the library (recommended), have no output (including and tags, as well as any whitespace) sent to the browser prior to instantiating the library, or turn output buffering on in php.ini. in /Users/dp/Documents/SitesDev/wordpress/wp-content/plugins/my-plugin/lib/Zebra/Zebra_Form.php on line 4052

有什么线索吗?还是Zebra_form不能这样使用?

我知道

自从你发布这个问题以来已经有一段时间了,但这就是我想出的地方我遇到了和你一样的错误,所以我查看了Zebra_Form.php并将第 4041 行注释掉到 4068 行。它之后起作用了。

你必须把

session_start();