2016-04-25 55 views
0

我的困境:FORM要PHP重疊?

我在我的主頁上有一個搜索表單,我想提交給php搜索功能,然後將其結果發佈到疊加層而不離開主頁面。

這是我的表單代碼:

<form method="post" id="searchform" action="external-content.php" > 
     <div> 
     <input class="input-text" name="keyword" id="s" value="Enter your text here..." onFocus="if (this.value == 'Enter your text here...') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Enter your text here...';}" type="text" /> 

     <input id="searchsubmit" value="Search" type="submit" /> 

     </div> 
</form> 

這裏是我的代碼覆蓋:

<div class="apple_overlay" id="overlay"> 
     <div class="contentWrap"></div> 
    </div> 
<script src="js/overlay/jquery.tools.min.js"></script> 
<script> 
$(function() { 
    $("a[rel]").overlay({ 

     mask: 'darkgrey', 
     effect: 'apple', 

     onBeforeLoad: function() { 
      var wrap = this.getOverlay().find(".contentWrap"); 
      wrap.load(this.getTrigger().attr("href")); 
     } 

    }); 
}); 
</script> 

疊加完美的作品時,我只是用一個簡單的按鈕來觸發覆蓋。表單調用PHP函數並顯示我想要顯示的數據,但它在不同的選項卡中打開數據。

我會編輯表單以使結果顯示在疊加層中(如果是這樣,怎麼樣?),還是腳本中有某些東西需要調整才能使這兩個元素一起工作?

回答

0

兩者尚未連接。您需要在表單中提供onsubmit事件,從服務器加載數據。

<form method="post" id="searchform" action="" onsubmit="showOverlay(); return false"> 

請確保您返回false,以便瀏覽器不發送表單本身。


提示:

<input class="input-text" name="keyword" id="s" value="Enter your text here..." onFocus="if (this.value == 'Enter your text here...') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Enter your text here...';}" type="text" /> 

可以是

<input class="input-text" name="keyword" id="s" placeholder="Enter your text here..." type="text" /> 
+0

colburton, 仍然打開PHP數據在新窗口中打開,而不是在它的數據覆蓋。 – user3230291

+0

要打開一個新窗口,必須具有類似window.open或target =「_ new」或target =「_ blank」的內容。刪除 – colburton