2014-01-29 9 views
0

폼이 확인 된 후 감사 페이지로 리디렉션하려고하는 사용자 지정 WP 테마가 있습니다. 매우 많은 다른 질문이 있다는 것을 알고 있지만 "헤더"트릭과 다른 모든 제안을 시도했지만 내 페이지는 contact.php 페이지로 돌아갑니다. 제출 버튼 위에 마우스를 올려 놓으면 (클릭하기 전에) mypageURL.com/thanks 대신 mypageURL.com/contact가 표시됩니다. 여기 내 코드가있다.PHP 폼이 감사 페이지로 리디렉션됩니다.

<?php 
//Verify the email address 
function isemail($email) { 
    return preg_match('|^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$|i', $email); 
} 
//set variables 
$error_name = false; 
$error_email = false; 
$error_message = false; 
//Get form values 
if (isset($_POST['contact-submit'])) { 
    $contact_name = ''; 
    $contact_email = ''; 
    $contact_subject = ''; 
    $contact_message = ''; 
    $contact_reciever = ''; 

    if (trim($_POST['contact_name']) === '') { 
     $error_name = true; 
    } else { 
     $contact_name = trim($_POST['contact_name']); 
    } 

    if (trim($_POST['contact_email']) === '' || !isemail(trim($_POST['contact_email']))) { 
     $error_email = true; 
    } else { 
     $contact_email = trim($_POST['contact_email']); 
    } 

    $subject = trim($_POST['contact_subject']); 

    if (trim($_POST['contact_message']) === '') { 
     $error_message = true; 
    } else { 
     $contact_message = stripslashes(trim($_POST['contact_message'])); 
    } 

    //Check for errors 
    if (!$error_name && !$error_email && !$error_message) { 
     //Get reciever email 
     if(get_theme_mod('custom_contact_form_mail') != '') $get_contact_reciever = get_theme_mod('custom_contact_form_mail') ; 
     $contact_reciever = $get_contact_reciever; 

     $the_subject = 'New message: ' . $contact_subject; 
     $the_message = 'Message from: ' . $contact_name . PHP_EOL . 'Email: ' . $contact_email . PHP_EOL . PHP_EOL . $contact_message . PHP_EOL ; 

     $the_headers = "Form " . $contact_email . PHP_EOL . 'Reply-To: ' . $contact_email . PHP_EOL . 'MIME-Version: 1.0' . PHP_EOL . 'Content-type: text/plain; charset=utf-8' . PHP_EOL . 'Content-Transfer-Encoding: quoted-printable' . PHP_EOL; 

     if (mail($contact_reciever, $the_subject, $the_message, $the_headers)) { 
      $contact_form_sent = true; 
     } else { 
      $contact_form_sent_error = true; 
     } 
    } else { 
     $contact_form_not_filled = true; 
    } 
} 

?> 

<?php get_header(); ?> 

<section id="content"> 

    <?php if (have_posts()) : while(have_posts()) : the_post(); ?> 

    <div class="white-section contact"> 
     <div class="container"> 
      <div class="row"> 
       <div class="span12"> 
        <?php if (current_user_can('edit_post', $post->ID)) 
         edit_post_link($link = __('You are logged in as an Administrator. Click this text to edit this page. This text will not show up if you are not logged in as Admin.', 'cht'), $before = '<i class="icon-edit"></i> ', $after = ''); 
        ?> 
        <div class="row"> 
         <div class="span6"> 
          <?php the_content(); ?> 
          <h4><?php _e('Contact info', 'cht') ?></h4> 
          <ul> 
          <?php if(get_theme_mod('custom_contact_info_name') != '') { ?> 
           <li><i class="icon-briefcase"></i> <?php print get_theme_mod('custom_contact_info_name') ?></li> 
          <?php } else { ?> 
           <li><i class="icon-briefcase"></i> Cloud Hoster Ltd.</li> 
          <?php } ?> 
          <?php if(get_theme_mod('custom_contact_info_address') != '') { ?> 
           <li><i class="icon-map-marker"></i> <?php print get_theme_mod('custom_contact_info_address') ?></li> 
          <?php } else { ?> 
           <li><i class="icon-map-marker"></i>Main Street, New York 45678</li> 
          <?php } ?> 
          <?php if(get_theme_mod('custom_contact_info_phone') != '') { ?> 
           <li><i class="icon-phone"></i> <?php print get_theme_mod('custom_contact_info_phone') ?></li> 
          <?php } else { ?> 
           <li><i class="icon-phone"></i> Phone: 555-555-5555 Fax: 444-444-4444</li> 
          <?php } ?> 
          <?php if(get_theme_mod('custom_contact_info_mail') != '') { ?> 
           <li><i class="icon-envelope-alt"></i> Email: <a href="mailto:<?php print get_theme_mod('custom_contact_info_mail') ?>"><?php print get_theme_mod('custom_contact_info_mail') ?></a></li> 
          <?php } else { ?> 
           <li><i class="icon-envelope-alt"></i> Email: <a href="mailto:[email protected]">[email protected]</a></li> 
          <?php } ?> 
          </ul> 
         </div><!-- span6 end --> 

         <div class="span6"> 
          <div id="map"></div> 
           <script> 
           jQuery(document).ready(function(){ 
            var map; 
            map = new GMaps({ 
             div: '#map', 
             <?php if(get_theme_mod('custom_google_map_lat') != '') { ?> 
              lat: <?php print get_theme_mod('custom_google_map_lat') ?>, 
             <?php } else { ?> 
              lat: 40.714353, 
             <?php } ?> 
             <?php if(get_theme_mod('custom_google_map_lng') != '') { ?> 
              lng: <?php print get_theme_mod('custom_google_map_lng') ?>, 
             <?php } else { ?> 
              lng: -74.005973, 
             <?php } ?> 
             zoom: 15, 
             zoomControl: true, 
             zoomControlOpt: { 
              style : 'SMALL', 
              position: 'TOP_LEFT' 
             }, 
             streetViewControl: false, 
            }); 

            map.addMarker({ 
             <?php if(get_theme_mod('custom_google_map_lat') != '') { ?> 
              lat: <?php print get_theme_mod('custom_google_map_lat') ?>, 
             <?php } else { ?> 
              lat: 40.714353, 
             <?php } ?> 
             <?php if(get_theme_mod('custom_google_map_lng') != '') { ?> 
              lng: <?php print get_theme_mod('custom_google_map_lng') ?>, 
             <?php } else { ?> 
              lng: -74.005973, 
             <?php } ?> 
            }); 
           }); 
           </script> 
         </div><!-- span6 end --> 
        </div><!-- row end --> 

        <div class="row"> 
         <div class="span12"> 
          <form action="<?php the_permalink(); ?>" method='post' name='contactform' id='contactform'> 
           <p><?php _e('Your name:', 'cht') ?></p> 
           <input type="text" class="input-box" name="contact_name" value="<?php if (isset($_POST['contact_name'])) echo $_POST['contact_name']; ?>" placeholder="<?php _e('Please enter your name.', 'cht') ?>"> 
           <p><?php _e('Email address:', 'cht') ?></p> 
           <input type="text" class="input-box" name="contact_email" value="<?php if (isset($_POST['contact_email'])) echo $_POST['contact_email']; ?>" placeholder="<?php _e('Please enter your email address.', 'cht') ?>"> 
           <p><?php _e('What kind of problems are you having?', 'cht') ?></p> 
           <input type="text" class="input-box" name="contact_subject" value="<?php if (isset($_POST['contact_subject'])) echo $_POST['contact_subject']; ?>" placeholder="<?php _e('Purpose of this message.', 'cht') ?>"> 
           <p class="right-message-box"><?php _e('How Can We Help You?', 'cht') ?></p> 
           <textarea class="input-box right-message-box message-box" name="contact_message" value="<?php if (isset($_POST['contact_message'])) echo stripslashes($_POST['contact_message']); ?>" placeholder="<?php _e('Your message.', 'cht') ?>"></textarea> 
           <button type='submit' class='submit-contact-form' name='submit' id="submit">Send your message</button> 
           <input type="hidden" name="contact-submit" id="contact-submit" value="true"> 
          </form> 
         </div><!-- span12 end -->     
        </div><!-- row end --> 

         <?php if (isset($contact_form_sent) && $contact_form_sent == true) : ?> 
          <div class="alert alert-success"><p><strong><?php _e('Success! ', 'cht') ?> </strong><?php _e('Your message has been sent.', 'cht') ?></p></div> 
         <?php elseif (isset($contact_form_sent_error) && $contact_form_sent_error == true) : ?> 
          <div class="alert alert-error"><p><strong><?php _e('Error! ', 'cht') ?> </strong><?php _e('Something went wrong. Please try again.', 'cht') ?></p></div> 
         <?php elseif (isset($contact_form_not_filled) && $contact_form_not_filled == true) : ?> 
          <div class="alert alert-error"><p><strong><?php _e('Error! ', 'cht') ?> </strong><?php _e('Fill out the form correctly and try again.', 'cht') ?></p></div> 
         <?php endif; ?> 

       </div><!-- span12 end --> 
      </div><!-- row end --> 
     </div><!-- conteiner end --> 
    </div><!-- white-section end --> 

    <?php endwhile; endif; ?> 

</section><!-- content end --> 

<?php get_footer(); ?> 

답변

0

실제로 트릭이 아닙니다. 원하는 작업을 정확하게 수행 할 수 있습니다.

if (mail($contact_reciever, $the_subject, $the_message, $the_headers)) { 
    $contact_form_sent = true; 
    header("Location: " . get_permalink($THANKYOU_PAGE_ID)); 
} 

헤더를 사용할 때 오류가 발생하지 않습니까? 그렇다면 후크를 만들고 페이지로드의 초기에 폼을 확인해야 할 수 있습니다.

귀하의 의견이 "그렇습니다. 오류가 발생합니다. 이전에 양식을 연결하면 어떻게되지 않습니까?"라고 가정하고 있습니다. 그럼 나의 좋은 친구는 나를 따라 ..

add_action('send_headers', 'form_verify'); 
function form_verify() { 
    // add form code here with header code 
} 
+0

경고 : 헤더 정보를 수정할 수 없습니다 - 헤더가 이미 /directory/page-contact.php에에 (출력 /directory/page-contact.php:7에서 시작)에 의해 전송 168 행 – user1707042

관련 문제