2014-06-26 28 views
0

我有一個包含這種形式的元件:如何在搜索表單元素的同一頁面上顯示搜索結果?

<?php 
echo $this->Form->create('PrototypeItem', array(
    'url' => array('instance' => $instance['PrototypeInstance']['slug']) 
    , 'class' => 'simple-search' 
    , 'action' => '/search' 

)); 
echo $this->Form->input('search', array(
    'label' => 'Search', 
    'type' => 'text' 
)); 
echo $this->Form->end('Search'); 
?> 

<!-- code for displaying search results here --> 

此前,該元素被稱爲位於site.com/realtor-documents/search頁面上,它工作得很好。

但是,設計師要求我將搜索表單移至site.com/realtor-文檔,以消除額外的點擊。所以表格現在在/ realtor-documents,但是當我提交時,它仍然會重定向到/ realtor-documents/search。我希望結果與表單/ realtor-documents一樣顯示在同一頁面上。我怎樣才能做到這一點?

+0

不太熟悉php,但我會建議通過ajax調用你的腳本/結果 – Mark

+0

如果你在這個頁面中搜索,請刪除'action'=>'/ search' – tungbk29

+0

你是否使用https://github.com/ CakeDC /搜索?如果沒有,你應該。 – mark

回答

0

這是因爲'action' => '/search',將其替換爲'action' => '',以便它將結果發送到同一頁上。

+0

或者更好的是''action'=> $ this-> action'([因爲有一個空白的'action'是不正確的](http://stackoverflow.com/questions/1131781/is-it-a-good-練習使用空的url-for-a-html-forms-action-attribute-a)) –

+0

這不起作用 - 我只是得到了404。它是來自不同插件的元素,所以當前操作不包含搜索邏輯。 – Kluny

+0

你有沒有試過這個''action'=>''' – Adeel

相關問題