Laravel request return to POST route - php

I have replaced my entity with Blog to explain better.
I have the following route:
Route::get('/blog-category', 'BlogController#showBlogCategory')
which shows a form with a dropdown of different blog categories and some other input fields related to the category
The form POSTs to the following:
Route::post('/blog-details', 'BlogController#showBlogDetails')
Here I validate the request the form and return back if there is an invalid blog category or if it is missing
This method is called showBlogDetails because the category and the other fields are passed on to the next view return view('blog-details', compact('blogCategoryData'))
In this view there is a form to fill in the rest of the blog details.
Both the blogCategoryData (each data has a hidden input field) and the blog details are POSTed to the following route:
Route::post('/blog-store', 'BlogController#store')
This is also validated using a Request but if it fails it tries to go back, which it can't do as only POST is allowed to get there.
I need the blog category fields before I can show the blog details and a Blog cannot be created without either stuff so I can't temporarily create one either.
This flow of selecting/filling in blog category fields and then entering details is a requirement so has to be done in that order, in 2 different pages.
So currently it is:
GET -> POST (validate) -> POST (validate)
What is the best way around this or how would I make my current flow work?

one way is to use javascript and of course ajax to fetch blog data and show corresponding section. first the page only shows categories drop down box. after changing that to a correct category page makes an ajax request and fetches data. then replaces it in a hidden 'div' and shows it.
another way is to bring replace the categories box in the previous page.

Related

How to filter post types with a select field?

I'm working on a Wordpress project and have a question.
I have a layout like shown below in the link to screenshot with a select field and boxes with news (two or more different post types). I want to filter with the select the post type so there should show up only the selected. How can i do that?
Thanks in advance.
If you're fine dropping the pagination and having all of your posts on a single page, one option is to use Isotope.js. In addition to being a very useful plugin, they have thorough documentation to figure out how to structure your code to get filtering working.
If the pagination is absolutely necessary, this becomes more complex. Here's the short hand-wavey version that needs testing: You can use JS to reload the page with an extra parameter added to the URL (ex: /your-page?filter=post_type_1). You'll need to register your custom URL parameter with WordPress. Then, in your PHP, you'll use that parameter data in your WP_Query (or whatever you're using to query posts) to grab only posts of that type. It would be smart to have a default, where if the filter parameter from the URL isn't present or doesn't match a post type you have in your site, you default to showing all posts.
This blog post walks through how to do this method of filtering more thoroughly: https://codepen.io/the_ruther4d/post/custom-query-string-vars-in-wordpress.

WP Custom Post Type Backend View

I have created a Custom Post Type with the Custom Post Type UI plugin.
I have added a number of custom fields which are connected to this custom post type.
I want to create a Backend View for the custom post type where the user can see the post without the ability to Edit the post.
I need help on the following issues:
Overriding the 'View' button shown for every entry to point to the 'Backend View' page
Creating the 'Backend View'
Edited due to a suggestion:
The Custom Post type that I have created isn't shown through the website it is meant as Booking, each Booking input is added as a post entry, which currently can only be viewed in Edit mode. Which creates a problem as I want the edit mode to be available to 'Super' Admins only.
Apart from the above the View button which is automatically shown for each entry directs you to the homepage, I want this to be either overriden and directed to a View page or completely removed so to not confuse the users.

Wordpress - User controlled sorting/filtering

I've been trying to find a solution to this, but haven't had a whole lot of luck.
I need to give the user control over which posts are being displayed on the homepage via selectboxes. Essentialy, a 'filter by' (list of categories) and a 'sort by' (date, name and a few other custom fields).
Is there anyway to do this and have the loop refresh dynamically?
Thanks!
Z
If you want a non-coding way to do it you could use the Types & Views plugin: http://wp-types.com/
Otherwise you'll need to use javascript or jQuery to trigger an update after the user selects the categories and other criteria. Something like a submit button that triggers an ajax post of the criteria selected which then retrieves the requested posts and updates the page content.

Implementing AJAX into posts

I am building a custom post type (CPT) that requires a form that users may choose to submit. Regardless, I want any user to be able to see the current summation of the results. This is similar to how to codex article on AJAX says WordPress uses it..
"Several themes and plugins also use Ajax; for instance, some post rating plugins use Ajax to store the visitor's rating in the database and then display an updated average rating." - http://codex.wordpress.org/AJAX
How can I create an element that shows an average rating from user inputs on a CPT entry?

Search form controller

I am trying to create a Generic Search form (Controller) object. As in my website I have 4 different search forms, like
at Start Page I have a search form and on List page I have again a search form with more filters and on product page Have a search form with product specific property filters.
And what I want is that when user comes back from product page to list page, all the filters should a selected again automatically and if the user was on page 3 (pagination) the he should land again on page 3. Similarly from list to start, all the selected options should be populated again.
Is there any example available?
You could store this information in session variables.
For example, each time a list page is loaded, its number could be added to a $_SESSION["page_number"]; variable. Then whenever the list page loads again (being navigated from the product page for instance), the session value is used to retrieve the last viewed page. The form filters and other options could be stored in the same manner.

Categories