2013-10-11 5 views
0

내 웹 사이트에서 이상한 행동을하고 있습니다. 사실 내 dB에 채워진 데이터를 삽입하는 기본 PHP 스크립트가있는 간단한 양식입니다.

내 컴퓨터에서 문제를 재현하지 못했지만 클라이언트 컴퓨터에서 원격 연결을 통해이를 관찰했습니다.

이상한 점은 때로는 내 스크립트에 $ _POST가 완전히 비어 있다는 것입니다. 양식이 잘 채워질 때가 있습니다. 그리고 나머지는 실제로 제대로 작동합니다.

문제가 발생하기 전에 제출할 때 대기 시간이 길어졌습니다. 여기

은 (당신이 볼로는 WP이야) 일부 코드 :

형태 :

<form id="filmform" action="<?php bloginfo('url'); ?>/post-film" method="post" enctype="multipart/form-data"> 
    <fieldset> 
     <p> 
      <label for="titre_film">Titre du film *</label> 
      <input type="text" name="titre_film" id="titre_film" value="<?php echo (isset($_SESSION["form"]["titre_film"])) ? $_SESSION["form"]["titre_film"] : "" ?>" style="width:300px"/> 
     </p> 
     <p> 
      <label for="affiche">Affiche du film</label> 
      <input type="file" name="affiche" id="affiche" /> 
     </p> 
     <p> 
      <label for="nom_realisateur">Nom du/des réalisateur(s) *</label> 
      <input type="text" name="nom_realisateur" id="nom_realisateur" value="<?php echo (isset($_SESSION["form"]["nom_realisateur"])) ? $_SESSION["form"]["nom_realisateur"] : "" ?>" style="width:200px" /> 
     </p> 
     <p> 
      <label for="nationalite_realisateur">Nationalité du/des réalisateur(s) *</label> 
      <input type="text" name="nationalite_realisateur" id="nationalite_realisateur" value="<?php echo (isset($_SESSION["form"]["nationalite_realisateur"])) ? $_SESSION["form"]["nationalite_realisateur"] : "" ?>" style="width:200px" /> 
     </p> 
     <p> 
      <label for="societe_production">Société de production *</label> 
      <input type="text" name="societe_production" id="societe_production" value="<?php echo (isset($_SESSION["form"]["societe_production"])) ? $_SESSION["form"]["societe_production"] : "" ?>" style="width:200px" /> 
     </p>[...] 

<input type="hidden" name="action" value="wp_handle_upload" /> 
     <p><input type="submit" name="wp-submit" value="Inscription" /> - <input type="button" value="Imprimer" onclick="window.print()" style="cursor:pointer" /> - <input type="reset" value="Remettre le formulaire à 0" style="cursor:pointer" /></p> 
    </fieldset> 
</form> 

내 스크립트를

<?php 
/* 
Template Name: Récupération données formulaire film 
*/ 

$array_field_required = array(
"categories_inscription", 
"titre_film", 
"reglement", 
"reglement2", 
"nom_realisateur", 
"email_societe_production", 
"societe_production_luxembourgeoise", 
"nationalite_realisateur", 
"producteur_delegue", 
"distribution" 
); 
$no_meta_for_those_fields = array(
"categories_inscription", 
"titre_film", 
"reglement", 
"reglement2", 
"action", 
"wp-submit", 
"email_societe_production", 
"redirect_to" 
); 

$array_errors = array(); 
$message_admin = ""; 

foreach($_POST as $key => $value)  { 
    $_SESSION["form"][$key] = $value; 
} 

foreach($array_field_required as $required_field)  { 
    if (!isset($_POST[$required_field]) || empty($_POST[$required_field])) { 
     $array_errors[] = $required_field; 
    } 
} 

if (sizeof($array_errors) > 0) { 
    wp_redirect(get_bloginfo('url') . "/inscrire-un-film?errors=" . implode(";", $array_errors)); 
    exit(); 
} 

$post = array(
"post_type"   => "film", 
"post_category"  => $_POST["categories_inscription"], 
"post_name"   => $_POST["titre_film"], 
"post_title"  => $_POST["titre_film"] 
); 
$post_id = wp_insert_post($post, false); 

if($post_id) { 
$unique = true; 
foreach($_POST as $key => $value)  { 
    if (!in_array($key, $no_meta_for_those_fields))  { 
     add_post_meta($post_id, $key, $value, $unique); 
    } 
} 
add_post_meta($post_id, 'actif', 0, true); 

if (! function_exists('wp_handle_upload')) require_once(ABSPATH . 'wp-admin/includes/file.php'); 
$uploadedfile = $_FILES['affiche']; 
$upload_overrides = array('test_form' => false); 

$movefile = wp_handle_upload($uploadedfile, $upload_overrides); 
$attachment = array(
    'post_mime_type' => $movefile["type"], 
    'guid' => $movefile["url"], 
    'post_parent' => $post_id, 
    'post_title' => $_FILES['affiche']["name"], 
    'post_content' => "", 
); 
$attach_id = wp_insert_attachment($attachment, $movefile, $post_id); 
if ($attach_id) { 
    set_post_thumbnail($post_id, $attach_id); 
} 
wp_redirect(get_bloginfo('url')."/droits-d-inscription"); 
} else { 
    wp_redirect(get_bloginfo('url')."/inscrire-un-film"); 
} 

exit(); 

당신이 어떤 생각을 가지고 있습니까 저를 도울 수 있습니까?

덕분에, 줄리앙

+0

코드 또는 예제가 있습니까? ... – Patrick

+2

음 ... 코드를 보는 것이 도움이 될 것입니다. P –

+0

세부 정보 필요 : 몇 개의 입력란을 제출 하시겠습니까? 파일을 업로드하고 있습니까? 클라이언트가 사용하는 브라우저/바이러스 백신/방화벽은 무엇입니까? – neelsg

답변

0

당신은 비어 있는지 찾기 위해 POST에 이중 검사를 추가 할 수 있습니다. 비어있는 경우 양식 페이지로 리디렉션을 추가하고 양식 제출이 예상대로 작동하지 않는다는 알림을 보내면 다시 시도하십시오.

코드를 게시하면 코드를 재현 할 수 있는지 확인할 수 있습니다. 당신이 이름을 입력 태그를 제출하는 경우

1

이 같이 할 수있는 "제출"

if (!isset($_POST['submit'])) { 
// or 
if (!array_key_exists('submit', $_POST)) { 
+0

고마워.하지만 이쪽은 괜찮아. ;) –

0

나는 당신의 문제에 대한 해결책을 찾기 위해 노력했다. 나는 PHP 매뉴얼에서 $ _POST에 대한 정보를 검색했다. 이 댓글을 발견했습니다 :

IE6, Apache2 및 mod_auth_sspi의 불쾌한 버그. 본질적으로 사용자가 제출 버튼을 너무 빨리 누르면 $ _POST (및 이와 동등한 항목)가 비어있게됩니다. 해결 방법은 Apache의 KeepAliveTimeout을 1로 설정하는 것입니다. 이는 사용자가 문제를 일으키기 위해 초 이내에 제출을 푸시해야한다는 것을 의미합니다.

도움이되기를 바랍니다.

steph

관련 문제