2016-12-26 2 views
0

フォームを作成していて、次の問題があります。フォームは完全にget_header()私のPHPコードで使用されていない場合に動作します。この関数をドキュメントに組み込むと、submitボタンをクリックしても何も行われません。Wordpress:get_header()を使用すると、送信ボタンにアクションがありません。

をどのように私は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(); ?>

答えて

0

ファイルにget_header()機能を使用してフォームを送信すると、_wpcf7_is_ajax_callフィールドがフォームに追加され、その値が '1'に設定されているため、WPキャッシュプラグインを使用していると思いますajaxリクエストを送信する

あなたのフォームは送信していますが、ajaxリクエストで送信しています。

+0

Contact Form 7の矛盾した振る舞いを除いて、あなたは絶対に正しいです。 Contact Form 7をどのようにしてサイト上の他のフォームとも矛盾させることはできませんが、依然として非常に感謝しています。どうもありがとう! –

+0

連絡先フォーム7でajax呼び出しを削除する設定があります –

0

それは間違っているものを見つけることは不可能です。おそらくjQueryのセレクタの競合ですが、コードをデバッグするにはソースを参照する必要があります。あなたのフォームとJavaScriptのソースを共有できますか?

+0

私はページソースコードを共有しました。 UPDを確認してください。 –

+0

問題はjavascriptファイルにあります。 get_header()関数にはjavascriptファイルが含まれています。すべてのjavascriptファイルをチェックし、jQueryサブミットまたはボタンクリックハンドラを探す必要があります。あなたのjavascriptファイルの1つの中に関数があり、送信イベントが発生しないようにします。 –

+0

ありがとう、私はそれをやります。あなたはそのような競合を見つけるのを助けることができる任意のソフトをお勧めできますか? –

関連する問題