开发者

Is there a way to submit a form and following a link at the same time?

I have a search form on a page with checkboxes to narrow down the results and my goal is to "keep" the contents of the form (checkbox that have been selected and such) when the user changes pages (there is a Zend paginator that takes care of makinbg pages for the searc results).

I use a variable in the $_SESSION called formInv that saves the content of the $_POST but in this particular case I must unset it just after I fill the $_POST because I don't want it to come over again if I browse other pages on the website.

The idea I got is to put an handler on the paginator that would call an ajax function that would submit the post into a dynamic php page for the sole purpose of saving the $_POST into formInv after submitting, of course I would have to modifiy the for "action" attribute via jQuery to point to the dynamic page, but the paginator already has a link that actually goes to the number of the page you click, so is it possible to submit the form, save the data into formInv a开发者_如何学运维nd then proceed to the clicked page?


IMO it's a good practice to use GET method if it's a search page. Then you can put the parameters directly in pages' links.


Remove the 'a hrefs' in the paginator and replace it with spans/li. Then bind an onclick event to the span/li which will add a hidden element to the form posts it. The hidden value will have the page no: of the next page. Thus you can paginate the result and maintain the data in the form.

<ul>
 <li onclick="Pagination(2,'filterform');"><span>2</span></li>
 <li onclick="Pagination(3,'filterform');"><span>3</span></li>
</ul>


function Pagination (page, formId)
{
$('<input>').attr({ type: 'hidden',name: 'p',value: page}).appendTo($("#"+formId));
$("#"+formId).submit();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜