0

I have a contact form that each time I refresh the page I get a prompt to resend all the data, I have added a header("location: location.php"); to the bottom of the form function to try and prevent this. However all I get is a Cannot Modify Header Information - Headers already sent error. Here is my code

<?php
/*
Template Name: form-test.php
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
include_once(ABSPATH. 'wp-content/themes/fiftyfityNew/contact-form.php');
get_header(); ?>

<script>
var i=0;
function test(){

for(i=0;i<=5;i++){
    document.write( "the number is" + i);
}
}
</script>
<script>
test();
</script>

<?php function make_user_feedback_form() {
    global $wpdb;
    global $current_user;

        $ufUserID = $current_user->ID;

        if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'updateFeedback' ) {
            $ufDataUpdate = $wpdb->insert( 'wp_user_feedback', array( 'date' => current_time('mysql'), 'responses' => $_POST["test"]) );
        }
        }?>
    <div id="form">
    <ol>
        <form method="post">
            <li><label for="test">Pick a date Babe:</label><input type="text" id="datepicker" name="test" value="" /></li> <!-- the (name="test") value is what the ('responses' => $_POST["test"]) value is talking too -->

            <li><input name="submit" type="submit" id="submit" class="submit button" value="Send feedback" /></li>
            <?php wp_nonce_field( 'updateFeedback' ); ?>
            <input name="action" type="hidden" id="action" value="updateFeedback" />
        </form>
    </ol>
    </div>
    <?php 

add_action('the_content','make_user_feedback_form');

header("location: http://localhost:8888/fiftyfity/?page_id=90");

?>

<?php
make_user_feedback_form();
?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>
1
  • 1
    This is a php question, not a wordpress question. – mor7ifer Feb 19 '12 at 13:14
1

You cannot send headers once you have sent ANY html to the browser...so if you want to do whatever it is you're trying to do with the headers, you'll need it to be before get_header().

On that note, I'm not sure what you're trying to do with the headers, but the 'Confirm Data Resubmission' prompt is coming from your browser. Do a fresh load of the page and then refresh and you shouldn't see it...but there's no way to get around it (because, again, it's from the browser)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.