Does Will Pagination Work with Forms Which Have Method="Post"

php get the post data when using pagination script

No, it's not possible. When a form is submitted (with method=post) to the server, that's one POST request. If you want to make another POST request, you need to make another POST request. If you click a link, that's not a POST request.

I'm assuming your scenario is something like a search form, which is submitted via POST and which returns several pages of results. In this case, POST is misused anyway. An HTTP POST request should be used for altering data on the server, like registering a new user or deleting a record. Just a search form is not data alteration, it's just data retrieval. As such, your form should be method=get. That will result in a URL with the form values as query parameters:

mainPage.php?search=foobar

You can then trivially create pagination URLs from that:

printf('<a href="mainPage.php?%s">...', http_build_query(array('page' => $i) + $ _GET));

Which will result in:

mainPage.php?search=foobar&page=2

This way all your requests are self contained GET queries.

Pagination doesn't work with POST action laravel 5

Yes pagination only works with get parameters.

You should use GET method for your search page. POST requests aren't meant for the purpose of displaying data. Why? There are many reasons, but to be short I will give you two examples:

  1. With GET parameters, let's say you are on sixth page - you can copy the link and paste it to friend and he will be able to view the same content as you. With POST this is impossible.

  2. You can not use back button with POST requests, if you manage to get pagination to work.

POST requests are useful when you need to submit data to the server, in order to create new record, for example.

So I suggest you to change your route type to GET and your search form method to GET.

pagination in form php

  1. Pass a $liststart value in as a parameter to your code (get it with $liststart = $_REQUEST['liststart']).
  2. Then adjust your loop to loop from $liststart to $liststart+10.
  3. Make a button that onClick, goes to your code above with the new $liststart value. for example for the 'next' button on the first page, use echo "' onClick='location.href=\"yourcodeabove.php?liststart=".$liststart+10."\";'>";

or if you prefer, you could do it without javascript by making the next and prev buttons their own forms. like this:

<FORM METHOD="LINK" ACTION="yourcodeabove.php?liststart="<?php $liststart+10 ?>">
<INPUT TYPE="submit" VALUE="next->">
</FORM>

close out your other form first (which doesn't look like it needs to be a form actually... could be a div just as well). forms usually have 'actions' and are submitted with buttons but since you'll have 2 buttons (next and prev) each could be their own form with either the javascript onClick or the form method.

How can I make pagination to work with filtering django?

the problem is inside your views.py.you can call allusername = allusername.filter(Q(nextstatus__icontains='Technical Investigation')) before calling Padignator after making all other logic and sorting try it.

@login_required()
def investigation(request):
search_post = request.GET.get('q')
# Code for the users to search for reception, partno, serialno, mconum, customername
if (search_post is not None) and search_post:
allusername = Photo.objects.filter(Q(reception__icontains=search_post) | Q(partno__icontains=search_post) | Q(
Customername__icontains=search_post) | Q(mcoNum__icontains=search_post) | Q(
serialno__icontains=search_post))
if not allusername:
allusername = Photo.objects.all().order_by("-Datetime")

else:
allusername = Photo.objects.all().order_by("-Datetime")

# Sort BY:
part = request.GET.get('sortType')
valid_sort = ["partno", "serialno", "Customername", "mcoNum"] # Sort the workshop data in ascending order acording to the part number, serial number, customer name and the MCO Number
if (part is not None) and part in valid_sort:
allusername = allusername.order_by(part)

page = request.GET.get('page')
allusername = allusername.filter(Q(nextstatus__icontains='Technical Investigation')) # new
paginator = Paginator(allusername, 10) # 1 page will only show 10 data, if more than 10 data it will move it to the next page.
try:
allusername = paginator.page(page)
except PageNotAnInteger:
allusername = paginator.page(1)
except EmptyPage:
allusername = paginator.page(paginator.num_pages)

context = {'allusername': allusername, 'query': search_post, 'order_by': part}
return render(request, 'workshop/investigation.html', context)

Django pagination is not working properly when using POST method in Search form

The idea is to pass the keyword and the location to the context.

def individual_home(request):
if request.method == 'GET':
keyword = request.GET.get('keywords')
print(keyword)
location = request.GET.get('location')
print(location)
ind = IndividualProfile.objects.get(user_id=request.user.id)

details = companyjob.objects.filter(
Q(job_title=keyword) | Q(qualification=keyword) | Q(skills_required=keyword) | Q(job_location=location) & Q(closing_date__gte=datetime.date.today()))
if details:
print(details)
count = details.count()
paginator = Paginator(details, 3)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)

return render(request, "individual_home.html",
{'keyword':keyword,'location':location,'jobs': page_obj,'count': count, 'ind': ind})
else:
return redirect("individual_homes")

change the padignation like this.

        <!--Pagination-->

<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
{% if jobs.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{ jobs.previous_page_number }}&keywords={{ keyword }}&location={{ location }}">Previous</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1" aria-disabled="True">Previous</a>
</li>
{% endif %}

{% if jobs.number|add:'-4' > 1 %}
<li class="page-item"><a class="page-link" href="?page={{ jobs.previous_page_number }}&keywords={{ keyword }}&location={{ location }}">…</a></li>
{% endif %}

{% for i in jobs.paginator.page_range %}
{% if jobs.number == i %}
<li class="page-item active" aria-current="page">
<span class="page-link">
{{ i }}
<span class="sr-only">(current)</span>
</span>
</li>
{% elif i > jobs.number|add:'-5' and i < jobs.number|add:'5' %}
<li class="page-item"><a class="page-link" href="?page={{ i }}&keywords={{ keyword }}&location={{ location }}"">{{ i }}</a></li>
{% endif %}
{% endfor %}

{% if jobs.paginator.num_pages > jobs.number|add:'4' %}
<li class="page-item"><a class="page-link" href="?page={{ jobs.number|add:'5' }}&keywords={{ keyword }}&location={{ location }}">…</a></li>
{% endif %}

{% if jobs.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ jobs.next_page_number }}&keywords={{ keyword }}&location={{ location }}">Next</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1" aria-disabled="True">Next</a>
</li>
{% endif %}
</ul>
</nav>

<!--end of Pagination-->

Using pagination with query string for a search form which has the method set to get in codeigniter

I can't believe this, I spent hours searching the web for a solution !
It was always with me.I should have opened the pagination library and viewed its content before I posted this question.Just one line and problem solved.

I added the following line in the index method.

$config['first_url'] = '/index.php/search/index/?q='.$q;



Related Topics



Leave a reply



Submit