2012-10-23 32 views
0

當點擊'完整訂單'時,我有一個聯繫表單來檢查某個字段是否爲空 它應該刷新頁面並顯示錯誤消息。當使用分頁時,在同一頁面上顯示PHP聯繫表單錯誤消息

但使用頁面重命名(一些簡單的方法來重命名頁面,並有相同的PHP多頁)

所以我把order.php?行動的聯繫方式IM =爲了

這是代碼:

<?php 
if(isset($_GET['action']) && $_GET['action'] != '') { 
    $action = $_GET['action']; 
} else { 

} 
?> 
<?php 
if(isset($action)) { 
    if($action == 'order') { 
?> 
<div class="container"> 

      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> 
       <fieldset> 


        <?php if(isset($hasError)) { //If errors are found ?> 
         <p class="alert-message error">Opps! Looks like you forgot to fill some specify field, please <b>go back</p> and fill the empty field.</p> 

        <?php } ?> 

        <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> 
         <div class="alert-message success"> 
          <p style="color: white;" ><strong>Your Order has been Successfully Sent!</strong></p> 
          <p style="color: white;" >Thank you for submitting your order, <strong><?php echo $pname;?></strong>! Please check your Private Messages folder at <strong><?php echo $forum;?></strong>, as we will get back to you soon. You will redirect back to homepage in less than 5 seconds.<meta HTTP-EQUIV="REFRESH" content="5; url=http://justxp.plutohost.net/jonydesigns/index.php"></p> 
         </div> 
        <?php } ?> 
         <div class="formwarp"> 
         <div class="tos1"> 
<input type="checkbox" id="new_info_yes" class="box1"> I agree to the <a href="#" style="color: #4fc5cf;" >Terms of Service</a>. 
    </div><br /> 
<div id="new_info_form"> 
        <div class="clearfix"> 
         <label for="subject"> 
          <span class="coloring">Forums Name:</span> 
         </label> 


              <div class="input"> 
          <select name="forumn" id="forumn" class="span6 required" role="select" aria-required="true"> 
           <option value="slct">Please select a forum</option> 
           <option value="hackforums">Hackforums</option> 
           <option value="sythe">Sythe</option> 
           <option value="rune-server">Rune-Server</option> 
          </select> 
         </div> 
        <br /> 
<div id="slct" class="colors">You haven't selected any forum.</div> 
<div id="hackforums" class="colors" style="display:none"> <span id="brdr">HackForums:</span> Discount Percent: <font color="green">10%</font> </div> 
<div id="sythe" class="colors" style="display:none"> <span id="brdr">Sythe:</span> Discount Percent: <font color="green">15%</font> </div> 
<div id="rune-server" class="colors" style="display:none"> <span id="brdr">Rune-Server:</span> Discount Percent: <font color="green">15%</font> </div> 
<script type="text/javascript"> 
    $(function() { 
     $('#forumn').change(function(){ 
      $('.colors').hide(); 
      $('#' + $(this).val()).show(); 
     }); 
    }); 
    </script> </div> 
<br /> 
        <div class="clearfix"> 
         <label for="name"> 
          <span class="coloring">Forums Username:</span> 
         </label> 
         <div class="input"> 
          <input type="text" name="forumuser" id="forumuser" value="" class="span6 required" role="input" aria-required="true" /> 
         </div> 
        </div> 

        <div class="clearfix"> 
         <label for="phone"> 
          <span class="coloring">Personal Name:</span> 
         </label> 
         <div class="input"> 
          <input type="text" name="pname" id="pname" value="" class="span6 required" role="input" aria-required="true" /> 
         </div> 
        </div> 


        <div class="clearfix"> 
         <label for="email"> 
          <span class="coloring">Email Address:</span> 
         </label> 
         <div class="input"> 
          <input type="text" name="email" id="email" value="" class="span6 required email" role="input" aria-required="true" /> 
         </div> 
        </div> 
             <div class="clearfix"> 
         <label for="email"> 
          <span class="coloring">PayPal Email Address:</span> 
         </label> 
         <div class="input"> 
          <input type="text" name="ppemail" id="ppemail" value="" class="span6 required email" role="input" aria-required="true" /> 
         </div> 
        </div> 

        <div class="clearfix"> 
         <label for="subject"> 
          <span class="coloring">Product Type</span> 
         </label> 
         <div class="input"> 
          <select name="product" id="product" class="span6 required" role="select" aria-required="true"> 
           <option>Please select a product\project</option> 
           <option>PSD to HTML</option> 
           <option>Web Design</option> 
           <option>Thread Design</option> 
           <option>Logo Design</option> 
           <option>Banner Design</option> 
           <option>Thread design + Signature</option> 
           <option>Other (Please type in additional information field)</option> 
          </select> 
         </div> 
        </div><br /> 
<div style="margin-left: -13%;" id="line"></div><br /> 
        <div class="clearfix"> 
         <span class="coloring">Information</span> 
         <div class="input"> 
          <textarea rows="8" name="message" id="message" class="span10 required" role="textbox" aria-required="true"></textarea> 
         </div> 
        </div> 
        <div class="clearfix"> 
         <span class="coloring">View Information</span> 
         <div class="input"> 
          <textarea rows="8" name="messageview" id="messageview" class="span10 required" role="textbox" aria-required="true"></textarea> 
         </div> 
        </div> 
        <div class="clearfix"> 
         <label for="phone"> 
          <span class="coloring">Additional Information:</span> 
         </label> 
         <div class="input"> 
          <input type="text" name="additional" id="additional" value="Additional information regarding the product" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" class="span6 required" role="input" aria-required="true" /> 
         </div> 
        </div> 
        <div class="clearfix"> 
         <label for="phone"> 
          <span class="coloring">PSD link:</span> 
         </label> 
         <div class="input"> 
          <input type="text" name="psd" id="psd" value="PSD link here" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" class="span6 required" role="input" aria-required="true" /> 
         </div> 
        </div> 
        <div class="clearfix"> 
         <label for="phone"> 
          <span class="coloring">Your Budget:</span> 
         </label> 
         <div class="input"> 
          <input type="text" name="money" id="money" value="$0.00 Enter your budget" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" class="span6 required" role="input" aria-required="true" /> 
         </div> 
        </div> 
        <div class="actionss"> 
         <input type="submit" value="Complete Order" name="submit" id="submitButton" title="Click here to submit your message!" /> 
        </div> 
       </fieldset> 
      </form> 
      </div> 
</div> 
</div> 
<script type="text/javascript"> 
$(document).ready(function(){ 

    $('input#upload_yes').change(function(){ 
     if($(this).is(':checked')) { 
      $("#upload_form").show(); 
     } else { 
      $("#upload_form").hide(); 
     } 
    }); 

    $('input#new_info_yes').change(function(){ 
     if($(this).is(':checked')) { 
       $("#new_info_form").slideDown(500); 
     } else { 
       $("#new_info_form").delay(300).slideUp(500);; 
     } 
    }); 

    //Trigger the change event so the divs are initially shown or hidden. 
    $('input[type=checkbox]').trigger('change'); 

}); 
</script> 
<?php 
    } 
    elseif($action == 'contact') { 
    ?> 
<!-- action=contact info here --> 
<?php 
    } 
} 
?> 

這將啓動頁面動作=爲了

<?php 
if(isset($action)) { 
    if($action == 'order') { 
?> 

它顯示錶格並且一切正常。 但是,當您填寫所有內容並單擊完成的訂單時,它將重定向到order.php並且不顯示任何警報,如果發送訂單,它應該顯示此警報:

   <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> 
        <div class="alert-message success"> 
         <p style="color: white;" ><strong>Your Order has been Successfully Sent!</strong></p> 
         <p style="color: white;" >Thank you for submitting your order, <strong><?php echo $pname;?></strong>! Please check your Private Messages folder at <strong><?php echo $forum;?></strong>, as we will get back to you soon. You will redirect back to homepage in less than 5 seconds.<meta HTTP-EQUIV="REFRESH" content="5; url=http://justxp.plutohost.net/jonydesigns/index.php"></p> 
        </div> 
       <?php } ?> 

如果有什麼是空的應該顯示這個錯誤:

   <?php if(isset($hasError)) { //If errors are found ?> 
        <p class="alert-message error">Opps! Looks like you forgot to fill some specify field, please <b>go back</p> and fill the empty field.</p> 

       <?php } ?> 

,但它不顯示錯誤可言,所做的只是您重定向到order.php頁,但如果成功的話,它只是發送電子郵件但不會顯示任何警報。

我該如何解決它或導致它發生的原因?

http://justxp.plutohost.net/jonydesigns/order.php?action=order

對不起,巨大的代碼,我只是不知道該怎麼問這個問題更乾淨。

+0

你在哪裏設置$ hasError? – whitelionV

回答

0

我解決的正確它,

我把錯誤部分移出頁面,開始,現在它檢查是否有錯誤,如果是,它會顯示錯誤或警報。

對不起,發佈這樣一個簡單的問題^^

0

當錯誤發生時,您不停止腳本執行,因此代碼的測試仍在繼續。

這不是一個理想的解決方案,但這樣你的代碼編寫...

你可以把一個模具()函數在這裏停下來:

<?php if(isset($hasError)) { //If errors are found ?> 
    <p class="alert-message error">Opps! Looks like you forgot to fill some specify field, please <b>go back</p> and fill the empty field.</p> 
    die(); //See me here! 
<?php } ?> 
+0

(可選)可以將邏輯添加到頁面操作中。檢查第一部分中的$ hasError,並在沒有它的情況下執行另一個操作(針對您的錯誤)。無論哪種方式,但骯髒。這是OOP或框架開始發光的地方。 – phpisuber01

+0

我不是在談論代碼本身,錯誤不會顯示在頁面上,一旦你點擊'完整的順序'這與GET頁面URL有關 – user1761494

相關問題