WordPress.org

Ready to get started?Download WordPress

Forums

Custom form code produces 'Cannot modify header' error (3 posts)

  1. artemisian
    Member
    Posted 2 years ago #

    I'm trying to create a front-end form for users to post a draft post (of a custom post type). It's working - the posts are being created - but after the form's sent, I get the 'cannot modify header information' error message.

    Specifically, something like this:

    Warning: Cannot modify header information - headers already sent by (output started at /home/psyche/public_html/testsite4/wp-content/themes/phew_test-2/page-fayres-form.php:9) in /home/psyche/public_html/testsite4/wp-includes/pluggable.php on line 934

    The file give in brackets is the page template containing all the form code. As for the line (9, here), I've found that if I edit out any of the php tags in the header, the line quoted in the error message is always the one containing the second php tag on the page (the first one of course contains the template name).

    The error message isn't appearing when the form page is initially loaded - only after the form is submitted. (I've also tried splitting the code into two pages, one for the form, one to process the data, and I still get the error message after the form is submitted.)

    I've checked functions.php for white space before and after the opening and closing php tags - all fine. I've checked wp-config, too, and that's fine except that there's no closing php tag - but as far as I can see, that's normal, because a clean download of WP shows the same thing.

    You can see the full code at http://pastebin.com/ce7HmjyP. (It's based on this: http://pastebin.com/j1anH8Gj.) It's not finished, obviously - I'm just trying to fix this particular header information before I finish the other details.

    Would really appreciate any ideas anyone has.

    Thanks!

  2. artemisian
    Member
    Posted 2 years ago #

    Ah!

    pluggable.php's line 934 is in the wp_redirect section. And on my code, at line 178, is 'wp_redirect( home_url() );'.

    I've just tried removing that, and now no error message. Which is brilliant!

    But I'd still like to understand what happened there, so if anyone can enlighten me, I'd really appreciate it!

  3. artemisian
    Member
    Posted 2 years ago #

    OK, looks like this might explain it. Good to know.

    Sorry for multiple postings. I'm going to go away and be quiet now. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.