Search Field choice re-directs to a certain page ...

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 543 Views - Last Post: 10 April 2019 - 02:23 PM Rate Topic: -----

#1 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 04-February 19

Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 03:54 PM

The video web script, that I'm using, has a search-field where if you enter a letter, for example 'c', several choices on a list drops-down to select from. If you choose one of those 'titles' you're redirected to the 'watch' page, but if you don't choose one, and just hit 'return', you are redirected to the 'search results' page, where you can select which 'title' to choose. I'd like assistance with getting every search-field search to redirect to the 'search results' page, not the 'watch' page. I'm not sure if this is a php or html issue. Here are some lines of code that may be related to this issue:

if ($pt->config->total_videos > 1000000) {
$get_videos = $db->where("MATCH (title) AGAINST ('$keyword') AND privacy = 0  ".$category.$date)->orderBy('id', 'ASC')->objectbuilder()->paginate(T_VIDEOS, $pt->page_number);
$pt->total_pages = $db->totalPages;
} else {
$get_videos = $db->where("title LIKE '%$keyword%' AND privacy = 0  ".$category.$date)->orderBy('id', 'ASC')->objectbuilder()->paginate(T_VIDEOS, $pt->page_number);
$pt->total_pages = $db->totalPages;



and here's some related html:

<form class="navbar-form navbar-left search-header" role="search" action="{{LINK search}}" method="GET">
                <div class="form-group">
                    <input type="text" class="form-control" id="search-bar" name="keyword" placeholder="{{LANG search_keyword}}" autocomplete="off" value="{{SEARCH_KEYWORD}}"> 
                    <?php
                    if (!empty($_GET['is_channel'])) {
                    ?>
                    <input type="hidden" name="is_channel" value="true">
                    <?php } ?>
		<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search" onclick="javascript:$('.search-header input').focus();"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
                </div>
                <div class="search-dropdown hidden"></div>
            </form>



any assistance is appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: Search Field choice re-directs to a certain page ...

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2287
  • View blog
  • Posts: 6,978
  • Joined: 15-January 14

Re: Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 04:19 PM

The code to do that isn't part of what you posted. Somewhere there is a Javascript click handler, I assume, that controls what happens when you click.
Was This Post Helpful? 0
  • +
  • -

#3 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 04-February 19

Re: Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 04:22 PM

Thank you, very helpful.

Could it be this:


<script>
$('.search-icon').on('click', function(event) {
	event.preventDefault();
	$('.search-bar').toggleClass('hidden');
});
$('#search-bar').keyup(function(event) {
	var search_value = $(this).val();
	var search_dropdown = $('.search-dropdown');
	if (search_value == '') {
		search_dropdown.addClass('hidden');
		search_dropdown.empty();
		return false;
	} else {
		search_dropdown.removeClass('hidden');
	}
    $.post('{{LINK aj/search}}', {search_value: search_value}, function(data, textStatus, xhr) {
    	if (data.status == 200) {
    		search_dropdown.html(data.html);
    	} else {
	       search_dropdown.addClass('hidden');
		   search_dropdown.empty();
		   return false;
    	}
    });
});
</script>


Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2287
  • View blog
  • Posts: 6,978
  • Joined: 15-January 14

Re: Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 04:54 PM

It doesn't look like it's redirecting there either, it looks like it's just adding the HTML sent by PHP. If you search in the Javascript or PHP code for the filename that it's going to you might find it.
Was This Post Helpful? 0
  • +
  • -

#5 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 04-February 19

Re: Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 05:05 PM

Much thanks again.
At ajax/search.php I see this:

<?php 
$data = array('status' => 400);
if (!empty($_POST['search_value'])) {
	$search_value = PT_Secure($_POST['search_value']);
	$search_result = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE title LIKE '%$search_value%' AND privacy = 0 LIMIT 10");
	if (!empty($search_result)) {
		$html = '';
		foreach ($search_result as $key => $search) {
			$search = PT_GetVideoByID($search, 0, 0, 0);
			$html .= "<div class='search-result'><a href='$search->url'>$search->title</a></div>";
		}
		$data = array('status' => 200, 'html' => $html);
	}
} 
?>



and on the related search html page I see this:

<script>
	jQuery(document).ready(function($) {
		pt_get_notifications({type:'new'});
		
		$("#get-notifications").click(function(event) {
			if ($('#notifications').css('display') == 'none') {
				var notfi_cont = $("ul.notfi-dropdown");
				
				if ($("span#new-notifications").html() != '') {
					$(this).find('span#new-notifications').empty();
				}

				pt_get_notifications({sa:1});
			}
		});

		setInterval(function(){
			pt_get_notifications({type:'new'});
		}, 6000);
	});

	function pt_get_notifications(args){
		if (!args) {
			args = {};
		}
		var notfi_cont = $("ul.notfi-dropdown");
		var notfi_set  = $("ul#notifications");
		
		defparams = {
			type: false,
			sa:false
		}

		options = Object.assign(defparams,args);
		data    = {'hash':$('.main_session').val()};

		if (options['type']) {
			data['t'] = options['type'];
		}

		if (options['sa']) {
			data['sa'] = options['sa'];
			notfi_set.find('i.spin').removeClass('hidden');
		}

		$.ajax({
			url: '{{LINK aj/get_notifications}}',
			type: 'GET',
			dataType: 'json',
			data:data
		})
		.done(function(data) {
			if (data.status == 200) {
				if (data.new) {
					$("span#new-notifications").html($('<b>',{
						text:data.new
					}));
				}
				else{
					notfi_set.find('b').text(data.len);
					notfi_set.find('ul').html(data.html);
				}			
			}
			else if(data.status == 304 && options['sa']){
				notfi_set.find('ul').html($("<li>",{
					class:'no-notifications',
					text: "{{LANG no_notifications}}"
				}));
			}

			if (data.count_messages > 0) {
				$('#new-messages').html('<b>' + data.count_messages + '</b>');
			} else {
				$('#new-messages').html('');
			}

			if (options['sa']) {notfi_set.find('i.spin').addClass('hidden');}
			
		})
		.fail(function() {
			console.log("error");
		});
	}
</script>





any additional guidance is appreciated
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3814
  • View blog
  • Posts: 13,870
  • Joined: 08-August 08

Re: Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 05:18 PM

    $search_result = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE title LIKE '%$search_value%' AND privacy = 0 LIMIT 10");


Do not put user supplied data in a query. There's a reason query builders exist, and you're violating it. That's making your code vulnerable to SQL injection attack.
Was This Post Helpful? 0
  • +
  • -

#7 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 04-February 19

Re: Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 05:35 PM

Thank you for your reply and for looking over the code, much appreciated,
however, I did not write this video web script, and preventing SQL injection is something I'll have to get back to.
Can you comment on my initial request regarding search, does this lat provided code shed any light on that issue?
Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2287
  • View blog
  • Posts: 6,978
  • Joined: 15-January 14

Re: Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 05:47 PM

The only URL I see is coming from the database. That's probably the "watch" URL.

If you want to always go to the search results page, why not just remove the whole auto-completion thing and just always submit the form? Pressing enter submits the form.
Was This Post Helpful? 0
  • +
  • -

#9 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 04-February 19

Re: Search Field choice re-directs to a certain page ...

Posted 08 April 2019 - 05:52 PM

Much thanks again.

Regarding "why not just ... just always submit the form? Pressing enter submits the form"
Can you provide a clue on how to make that happen?
Any help is appreciated
Was This Post Helpful? 0
  • +
  • -

#10 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2287
  • View blog
  • Posts: 6,978
  • Joined: 15-January 14

Re: Search Field choice re-directs to a certain page ...

Posted 09 April 2019 - 10:38 AM

With a regular submit button, and removing the code that sends the ajax request and shows the list.
Was This Post Helpful? 0
  • +
  • -

#11 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 04-February 19

Re: Search Field choice re-directs to a certain page ...

Posted 09 April 2019 - 11:00 AM

Thanks again for your reply.

Rather than adding a submit button, I'm trying to find a solution where just like now when I entered a partial search like the letter "c", in the search field and hit "enter" on the keyboard, and get re-directed to the search-results page, I'd like to modify so anything entered into search field, including the full title, get re-directed to the search-results page.

Any comments/guidance/solution is appreciated
Was This Post Helpful? 0
  • +
  • -

#12 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2287
  • View blog
  • Posts: 6,978
  • Joined: 15-January 14

Re: Search Field choice re-directs to a certain page ...

Posted 09 April 2019 - 11:09 AM

But it sounds like you have that. Type something, press enter, it submits.
Was This Post Helpful? 0
  • +
  • -

#13 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 04-February 19

Re: Search Field choice re-directs to a certain page ...

Posted 09 April 2019 - 11:20 AM

Thanks again, yes I have that, except when a full 'title' is shown in the search field drop-down, if you choose one of those 'titles' you're redirected to the 'watch' page, but i'd like all search field selections choices to be re-directed to the results page (not the 'watch' page).

any additional guidance/assistance is welcomed
Was This Post Helpful? 0
  • +
  • -

#14 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2287
  • View blog
  • Posts: 6,978
  • Joined: 15-January 14

Re: Search Field choice re-directs to a certain page ...

Posted 09 April 2019 - 12:47 PM

Your form uses the get method to submit. So, the easiest way to do that would probably just be to have PHP print the URL for the search results page with the search query in the querystring. The other method is to add a Javascript click handler to the links in the drop down to change what happens and do the same thing, redirect to the results page with the query in the querystring.
Was This Post Helpful? 0
  • +
  • -

#15 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 04-February 19

Re: Search Field choice re-directs to a certain page ...

Posted 09 April 2019 - 01:04 PM

Much thanks for your suggestions/guidance.
Of course, now I'm going to have to figure how how to those things.

When you suggest "have PHP print THE URL for the search results page with THE search query in the querystring", do you mean it could be coded to have "have PHP print the URL for the search results page with ANY/ALL search query in the querystring"?

Regarding "add a Javascript click handler..."

any further explanation or example would be greatly appreciated
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2