我有以下代碼。我試圖阻止我的頁面在頁面刷新後使用標題(「location:location.php」)重新提交表單;不過,我得到以下列出試圖阻止刷新頁面重新提交表格
錯誤
Warning: Cannot modify header information - headers already sent by (output started at /Users/anderskitson/Sites/fiftyfity/wp-content/themes/fiftyfityNew/contact-form copy.php:7) in /Users/anderskitson/Sites/fiftyfity/wp-content/themes/fiftyfityNew/contact-form copy.php on line 68
守則錯誤
<?php
/*
Template Name: form-test.php
*/
?>
<?php include_once(ABSPATH . 'wp-admin/includes/plugin.php'); ?>
<? include_once(ABSPATH. 'wp-content/themes/fiftyfityNew/contact-form.php'); ?>
<?php
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the wordpress construct of pages
* and that other 'pages' on your wordpress site will use a
* different template.
*
* @package WordPress
* @subpackage Starkers
* @since Starkers 3.0
*/
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(); ?>
http://stackoverflow.com/questions/2938777/headers-already-sent的可能重複 – 2012-02-18 08:42:16