Я создаю форму и имею следующую проблему. Форма отлично работает, когда get_header()
не используется в моем PHP-коде. Как только я включу эту функцию в документ, нажатие на кнопку submit
ничего не делает.Wordpress: никаких действий при отправке кнопки при использовании get_header()
- страница с
get_header()
включена, TwentySixteen тема по умолчанию: http://eventboss.org/add-item-with-header/ - страница без
get_header()
: http://eventboss.org/add-property/
Как я могу сделать Post Review
(кнопка Добавить) работа с get_header()
в коде? И какой лучший способ отслеживать эти ошибки в будущем? Я не вижу ошибки в консоли браузера. Спасибо заранее.
UPD. Исходный код страницы Код:
<?php
/*
Template Name: Rate Wine Form Header
*/
?>
<?php
if('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == "new_post") {
\t // Do some minor form validation to make sure there is content
\t if (isset($_POST['submit'])) {
\t \t $error = "";
\t if (!empty($_POST['title'])) {
\t \t $title = $_POST['title'];
\t } else {
\t \t $error .= "Please add a title<br />";
\t }
\t if (!empty($_POST['description'])) {
\t \t $description = $_POST['description'];
\t } else {
\t \t $error .= "Please add a description<br />";
\t }
\t if (!empty($_POST['post_tags'])) {
\t \t $post_tags = $_POST['post_tags'];
\t } else {
\t \t $error .= "Please add some keywords<br />";
\t }
\t \t if (!empty($_POST['winerating'])) {
\t \t $post_tags = $_POST['winerating'];
\t } else {
\t \t $error .= "Please add some keywords<br />";
\t }
\t \t // IMAGE VALIDATION - CHECK IF THERE IS AN IMAGE AND THAT ITS THE RIGHT FILE TYPE AND RIGHT SIZE
\t \t if ($_FILES) {
\t \t \t foreach ($_FILES as $file => $array) {
\t \t \t \t //Check if the $_FILES is set and if the size is > 0 (if =0 it's empty)
\t \t \t \t if(isset($_FILES[$file]) && ($_FILES[$file]['size'] > 0)) {
\t \t \t \t \t $tmpName = $_FILES[$file]['tmp_name'];
\t \t \t \t \t list($width, $height, $type, $attr) = getimagesize($tmpName);
\t \t \t \t /*if($width!=10 || $height!=10)
\t \t \t \t {
\t \t \t \t \t $error .= "Image is to small<br />";
\t \t \t \t \t unlink($_FILES[$file]['tmp_name']);
\t \t \t \t }*/
\t \t \t \t // Get the type of the uploaded file. This is returned as "type/extension"
$arr_file_type = wp_check_filetype(basename($_FILES[$file]['name']));
$uploaded_file_type = $arr_file_type['type'];
// Set an array containing a list of acceptable formats
$allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png');
// If the uploaded file is the right format
if(in_array($uploaded_file_type, $allowed_file_types)) {
\t \t \t \t } else { // wrong file type
\t \t \t \t $error .= "Please upload a JPG, GIF, or PNG file<br />";
\t }
\t \t \t \t } else {
\t \t \t \t $error .= "Please add an image<br />";
\t \t \t \t }
\t \t \t } // end for each
\t \t } // end if
\t \t $tags = $_POST['post_tags'];
\t \t $winerating = $_POST['winerating'];
\t \t // ADD THE FORM INPUT TO $new_post ARRAY
\t \t if (empty($error)) {
\t \t \t $new_post = array(
\t \t \t 'post_title' \t => \t $title,
\t \t \t 'post_content' \t => \t $description,
\t \t \t 'post_category' \t => \t array($_POST['cat']), // Usable for custom taxonomies too
\t \t \t 'tags_input' \t => \t array($tags),
\t \t \t 'post_status' \t => \t 'publish', // Choose: publish, preview, future, draft, etc.
\t \t \t 'post_type' \t => \t 'post', //'post',page' or use a custom post type if you want to
\t \t \t 'winerating' \t => \t $winerating
\t \t);
\t \t //SAVE THE POST
\t \t $pid = wp_insert_post($new_post);
//KEEPS OUR COMMA SEPARATED TAGS AS INDIVIDUAL
\t \t wp_set_post_tags($pid, $_POST['post_tags']);
\t \t //REDIRECT TO THE NEW POST ON SAVE
\t \t $link = get_permalink($pid);
\t \t wp_redirect($link);
\t \t //ADD OUR CUSTOM FIELDS
\t \t add_post_meta($pid, 'rating', $winerating, true);
\t \t
\t \t //INSERT OUR MEDIA ATTACHMENTS
if (!function_exists('wp_generate_attachment_metadata')){
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload($file, $pid);
}
}
if ($attach_id > 0){
//and if you want to set that image as Post then use:
update_post_meta($pid,'_thumbnail_id',$attach_id);
}
\t \t \t /*//INSERT OUR MEDIA ATTACHMENTS
\t \t \t if ($_FILES) {
\t \t \t \t foreach ($_FILES as $file => $array) {
\t \t \t \t $newupload = insert_attachment($file,$pid);
\t \t \t \t // $newupload returns the attachment id of the file that
\t \t \t \t \t // was just uploaded. Do whatever you want with that now.
\t \t \t \t }
\t \t \t } // END THE IF STATEMENT FOR FILES
\t \t \t */
\t \t \t
\t \t } // END SAVING POST
\t } // END VALIDATION
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
//POST THE POST YO
do_action('wp_insert_post', 'wp_insert_post');
?>
<?php get_header(); // if this function is included the button doesn't work!!! ?>
\t \t <div id="container">
\t \t \t <div id="content" role="main">
<?php if (have_posts()) while (have_posts()) : the_post(); ?>
\t \t \t \t <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
\t \t \t \t \t <?php if (is_front_page()) { ?>
\t \t \t \t \t \t <h2 class="entry-title"><?php the_title(); ?></h2>
\t \t \t \t \t <?php } else { ?>
\t \t \t \t \t \t <h1 class="entry-title"><?php the_title(); ?></h1>
\t \t \t \t \t <?php } ?>
\t \t \t \t \t <div class="form-content">
\t \t \t \t \t <?php
\t \t \t \t \t \t if (!empty($error)) {
\t \t \t \t \t \t \t echo '<p class="error"><strong>Your message was NOT sent<br/> The following error(s) returned:</strong><br/>' . $error . '</p>';
\t \t \t \t \t \t } elseif (!empty($success)) {
\t \t \t \t \t \t \t echo '<p class="success">' . $success . '</p>';
\t \t \t \t \t \t }
\t \t \t \t \t ?>
\t \t \t \t \t \t <?php the_content(); ?>
\t \t <!-- WINE RATING FORM -->
\t \t <div class="wpcf7">
\t \t <form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data">
\t \t \t <!-- post name -->
\t \t \t <fieldset name="name">
\t \t \t \t <label for="title">Wine Name:</label>
\t \t \t \t <input type="text" id="title" value="" tabindex="5" name="title" />
\t \t \t </fieldset>
\t \t \t <!-- post Category -->
\t \t \t <fieldset class="category">
\t \t \t \t <label for="cat">Type:</label>
\t \t \t \t <?php wp_dropdown_categories('tab_index=10&taxonomy=category&hide_empty=0'); ?>
\t \t \t </fieldset>
\t \t \t <!-- post Content -->
\t \t \t <fieldset class="content">
\t \t \t \t <label for="description">Description and Notes:</label>
\t \t \t \t <textarea id="description" tabindex="15" name="description" cols="80" rows="10"></textarea>
\t \t \t </fieldset>
\t \t \t <!-- wine Rating -->
\t \t \t <fieldset class="winerating">
\t \t \t \t <label for="winerating">Your Rating</label>
\t \t \t \t <input type="text" value="" id="winerating" tabindex="20" name="winerating" />
\t \t \t </fieldset>
\t \t \t <!-- images -->
\t \t \t <fieldset class="images">
\t \t \t \t <label for="bottle_front">Front of the Bottle</label>
\t \t \t \t <input type="file" name="bottle_front" id="bottle_front" tabindex="25" />
\t \t \t </fieldset>
\t \t \t <fieldset class="images">
\t \t \t \t <label for="bottle_rear">Back of the Bottle</label>
\t \t \t \t <input type="file" name="bottle_rear" id="bottle_rear" tabindex="30" />
\t \t \t </fieldset>
\t \t \t <!-- post tags -->
\t \t \t <fieldset class="tags">
\t \t \t \t <label for="post_tags">Additional Keywords (comma separated):</label>
\t \t \t \t <input type="text" value="" tabindex="35" name="post_tags" id="post_tags" />
\t \t \t </fieldset>
\t \t \t <fieldset class="submit">
\t \t \t \t <input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" />
\t \t \t </fieldset>
\t \t \t <input type="hidden" name="action" value="new_post" />
\t \t \t <?php wp_nonce_field('new-post'); ?>
\t \t </form>
\t \t </div> <!-- END WPCF7 -->
\t \t <!-- END OF FORM -->
\t \t \t \t \t \t <?php wp_link_pages(array('before' => '<div class="page-link">' . __('Pages:', 'twentyten'), 'after' => '</div>')); ?>
\t \t \t \t \t \t <?php edit_post_link(__('Edit', 'twentyten'), '<span class="edit-link">', '</span>'); ?>
\t \t \t \t \t </div><!-- .entry-content -->
\t \t \t \t </div><!-- #post-## -->
\t \t \t \t <?php comments_template('', true); ?>
<?php endwhile; // end of the loop. ?>
\t \t \t </div><!-- #content -->
\t \t </div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Вы были абсолютно правы, за исключением того факта, что это противоречивое поведение Contact Form 7. Не знаю, как сделать контактную форму 7 не противоречащей остальным формам на сайте, все равно очень благодарным за ответ. Большое спасибо! –
была какая-то настройка для устранения ajax-звонка в контактной форме 7 –