Help with displaying Form when page appears

Thanks for all the previous help. The web script I’m trying to modify lets you select categories and subcategories and displays those filtered results. I’m trying to modify it so that subcategory pages can be searched by keyword (currently, the script only searches by keyword for the whole site, doesn’t just search sub-category results). It may help to know that when a sub-category page is displayed the url is, for example:…com/videos/category/2/sub__626

The current html code shows this

<?php if ($pt->page == 'category' && $pt->show_sub == true) { ?>

<script type="text/javascript">
$(document).on('change', '#category_id', function(event) {
	id = $(this).val();
$(document).on('change','#sub_categories_', function(event) {
	window.location.href = site_url+'/videos/category/<?php echo($_GET['id']) ?>/'+$('#sub_categories_').val();

to display the Search Form (that I’ve added to the html page):

<form action="search.php" method="GET" id="sub-search">
<input id="search" name="keywords" type="text" placeholder="Type here">
<input type="submit" value="Search" />

based on the posted codes above, would something like this work in the php?:

<?php if ($pt->page == 'category' && $pt->show_sub == true) { 

this example didn’t work, but maybe you could provide some guidance, as to what might work?

Any help/guidance/comment with triggering the Form to appear, upon sub_category page being displayed, is appreciated.

Well, Do you mean you want to change the appearance depending on the page you are on?
If you have sub pages such as you show com/videos/category…whatever, you can find the page you are on using PHP code. Loosely like this:

$page = basename($_SERVER['PHP_SELF']);
if ($page=="ADMIN.php") {
    Some code...
} elseif ($page=="categories.php") {
    Some Other code...

Also, you can check if the starting part of the page name is something, too. Loosely again, like this:

$page = basename($_SERVER['PHP_SELF']);
if (substr($page, 0, 5)=="ADMIN") {
    ADMIN code...
} elseif (substr($page, 0, 10)=="categories") {
    ...handle all pages that start with "categories"...

Is that what you are asking about?

Much thanks for your reply. Sorry, I was unclear.
Regarding “you can find the page you are on using PHP code”, I’m not trying to find a page, I am trying to have a search Form appear when the displayed page is a subcategory page

HUH? If you have a subcategory page, just change the code I showed with the name of the page?

OR, do you mean you want the screen to alter based on a click on the screen. You can do that in a couple different ways. If a drop-down is clicked, you can use JS to call a routine and in that routine, load the values of another drop-down using an AJAX call to load the new values.

If you mention load data when a page is displayed, you do that in HTML and PHP. If you want to do it dynamically after the page is already loaded, you can do it with JS/AJax…

Thanks again for your reply.
Sorry, for any confusion. Regarding naming the page, there are about 100 subcategories, and I’m trying to find a solution where when any subcategory page is chosen from the dropdown list, the page that appears (for any subcategory displayed page) will show the Search Form.

Any additional help is welcomed

Well, you can keep the options selected in the $_SESSION variable and post back to the same page.
Then, when you load the drop-down’s with values, set the one(s) selected showing it is already picked.
Then, populate the rest of the page accordingly.

OR, you can use JS and AJax to load the info once selected. You do this by using an onchange() call in the drop-down which would call a small routine to load the requested data from another php file and load it into the area where you want to display it.

The first way is just a post to the same page. The second is more complicated requiring another file that would grab the info you need.

Do you understand these two options?

Thank you again for your info.
Currently, the drop-down successfully loads the data related to whichever sub-category is selected. I’d like a search form to appear when that takes place. Essentially, when a subcategory populated page appears there is a search form on that page.

So, when you say “using an onchange() call in the drop-down which would call a small routine to load the requested data”, is the ‘requested data’ that you’re referring to a Search Form?

Okay, when you say the drop-down successfully loads the data related to… Does this happen using a drop-down post or JS/JQ?

If the dropdown which is posted, then, just display the needed DIV. If handled by a JS/JQ, then have it also SHOW a hidden form. A hidden form is just a < DIV > that has an ID attached to it. And, when the JS runs for the drop-down, have it also show the form. You can HIDE the form when the options are put in place.

Sponsor our Newsletter | Privacy Policy | Terms of Service