2013-03-02 6 views
2

내 Wordpress 사이트 (하드 코딩 됨)에 매우 기본적인 문의 양식을 작성 했으므로 제대로 작동하지 않습니다. XAMPP를 통해 로컬에서 올바르게 작동하며, 필자가 누락되었지만 도움이 될 것이라고 확신합니다. 사전에 감사드립니다!. 나는 또한 내가 만든 템플릿을 사용하고있다.Wordpress 문의 양식

<?php /* Template Name: contact */?> 

<?php get_header(); ?> 

<?php 

//vars declared to store form input 
$name=$email=$comment=$phone=""; 
//Error vars - to relay error message to the form 
$nameError=$emailError=$commentError=""; 
$error_message=""; 
$sentMessage=""; 
$status=0; //Will monitor if all fields have no errors and increment if so. 

function sanitise_var($string){ 
    htmlentities($string); 
    strip_tags($string); 
    return stripslashes($string); 
} 

if(isset($_POST['submitted'])){ 

if($_POST['name']==""){ 
    $nameError="Please enter a name"; 
    $error_message="Oops, error in the form. Please check"; 

} 

else { 
    $name=$_POST['name']; 
    ++$status; 

} 

if($_POST['email'] == "" || !preg_match("/^[a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", $_POST['email'])){ 
    $error_message="Oops, error in the form. Please check"; 
    $emailError="Please enter a valid email"; 

} 

else{ 
    $email=$_POST['email']; 
    ++$status; 
} 

if(!$_POST['phone']=="") $phone=$_POST['phone']; 

if($_POST['comment']==""){ 
    $error_message="Oops, error in the form. Please check"; 
    $commentError="Please enter a message"; 
} 

else{ 
    $comment=$_POST['comment']; 
    ++$status; 

} 


}//submitted if statement 


if($status==3 && $_POST['submitted']){ 
    $sentMessage="From: $name, email: $email, Phone: $phone, Comment: $comment"; 
    wp_mail("[email protected]", "From Android Scoop contact form", $sentMessage); 
    echo "Thanks, your email was sent successfully!"; 
} 

else{ 

echo<<<SOQ 

<div class="entry-content">   

    <h1 class="entry-title">Contact</h1> 

     <p class="contact"> 
      If you have a query drop us a line using the form below. We're always happy to hear from people with ideas for posts and content they'd like to   feature or maybe write about. Or maybe you just have some feedback you'd like to share with us. Why not just swing by and say hello. 
     </p>  
     <p class="requiring">* Denotes required fields</p>  

     <div class="form_left">  

    <form action="/contact/" method="POST"> 
       <p><label>Name:</label><input type="text" name="name" value="$name"/></p> 
       <p class="error">$nameError</p> 
       <p><label>Email</label><input type="text" name="email" value="$email"/></p> 
       <p class="error">$emailError</p> 
       <p><label>Phone:</label><input type="text" name="phone" value="$phone"/></p> 
       <input type="hidden" name="submitted" value="yes"/> 
       <input type="submit" value="Send your message"/>       
     </div> 

     <div class="form_right">   
       <p><label>Message:</label><br/><textarea name="comment" rows="20" cols="20">$comment</textarea></p> 
       <p class="error">$commentError</p> 
      </form> 
     </div> 
</div> 

SOQ; 워드 프레스에 대한하지만 규칙이 이동 일반 PHP로 인식하고, 당신이 의견에 나를 대답 내용에 따라하지

} 
?> 

<?php get_footer();?> 
+0

무엇이 오류입니까? 작동하지 않는 것은 매우 모호합니다 –

+0

죄송합니다 .. 예 ... 양식을 확인했지만 제출하지 않고 페이지를 찾을 수 없습니다. 내 로컬 서버에서 로컬로 잘 작동하므로 wordpress 때문인지 궁금하네요. –

+0

Mr Alien이 맞습니다 -이게 도움이 될 것입니다. http://stackoverflow.com/questions/4369/how-to-include-php-files-that-require-an-absolute-path – McNab

답변

3

시도 여기있다 같은 :

<form action="" method="POST"> 

그와 같은 다른 것으로 첫 번째 입력 필드의 이름 매개 변수의 이름을 변경하려고 작동하지 않는 경우 :

<input type="text" name="myname" value="$name"/> 
+0

아니 .. 나는 모든 종류를 시도했지만 아무 것도 작동하지 않는 것 같습니다. 매우 실망하고 있습니다. 여기에 http://androidscoop.co.uk/contact/ 페이지가 있습니다. 내 마지막 시도는 당신의 제안이었습니다 .. –

+0

위의 답변에 제안을 한 번 더 추가했습니다. 나는 당신의 웹 사이트에서 그것을 시도하고 첫 번째 입력 필드에 대한 "이름"매개 변수의 수정이 작동하는 것처럼 보였다. – user850010

+0

슈퍼 스타! 완벽하게 고마워요.하지만 어떻게 해결했는지 모르겠습니다. 내 어리 석음 때문에 내가 너를 투표 할 수 없어서 미안해. –

2

오전, 오류가 작업에 대한 빈 값을 사용

<form action="/contact/" method="POST"> 
       ----^---- 
+0

그래, 한번 제출 된 내용을 검증하기 위해 스크립트가 다시 실행되는 것처럼 로컬에서 모두 괜찮은 이유는 PHP 폼에 관한 일반적인 규칙을 알고 있습니다. 또한/contact /, the_permalink();에 게시를 시도했습니다. 절대 URL은 확실하고 아무 것도 작동하지 않습니다. 로컬에서 작동하는 방법이 이상하게 보입니다. 내가 뭔가 Wordpress와 관련이 없는지 궁금합니다. –