Post by scottyboyyy » Sun Apr 17, 2022 8:00 pm

I am having a strange issue where the value of the search bar is "a".

If I search for cars:
.com/index.php?route=product/search&search=cars

The search bar in the header has a value of a instead of cars

Code: Select all

if (isset($this->request->get['search'])) {
			$search = $this->request->get['search'];
		} else {
			$search = '';
		} 

When I do this: print_r($this->request->get['search']); it will say "cars" but the search bar remains saying "a".

Any idea what could be causing this?

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by straightlight » Sun Apr 17, 2022 8:33 pm

OC version.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by scottyboyyy » Mon Apr 18, 2022 6:18 am

Latest version.

So strange as within the controller.php I can get the correct search term, I can print_r / echo it. But when passing it into the value on the input search bar it's replaced with an "a". I thought it would be javascript doing it but I see nothing that would.

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by ADD Creative » Mon Apr 18, 2022 7:11 am

Shouldn't it be $data['search'] and not $search?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by straightlight » Mon Apr 18, 2022 7:58 am

Apply a:

Code: Select all

var_dump($search);
below the $search condition. Also, you'd need to specify in your service request where the $search variable is used and how. Partial code posted.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by by mona » Mon Apr 18, 2022 6:52 pm

if you want to know what goes to a view, always reference the last $data['search'] assignment.

In this case it depends which search bar you are referring to.

The common search bar is done via controller/common/search.php and it's associated view

Code: Select all

		if (isset($this->request->get['search'])) {
			$data['search'] = $this->request->get['search'];
		} else {
			$data['search'] = '';
		}

Code: Select all

<input type="text" name="search" value="{{ search }}" placeholder="{{ text_search }}" class="form-control input-lg" />
the output of that controller is embedded in the controller/common/header.php via:

Code: Select all

$data['search'] = $this->load->controller('common/search');
The main search bar is done via controller/product/search.php and it's associated view

Code: Select all

		if (isset($this->request->get['search'])) {
			$search = $this->request->get['search'];
		} else {
			$search = '';
		}
		
		...... lots of stuff here ....
		
		
		$data['search'] = $search;

Code: Select all

<input type="text" name="search" value="{{ search }}" placeholder="{{ text_keyword }}" id="input-search" class="form-control" />
Last edited by by mona on Mon Apr 18, 2022 9:52 pm, edited 1 time in total.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Mon Apr 18, 2022 8:40 pm

[ code ]
[ code ]
<input type="text" name="search" value="{{ search }}" placeholder="{{ text_search }}" class="form-control input-lg" />
? :ponder:

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by scottyboyyy » Tue Apr 19, 2022 5:09 am

Code: Select all

if (isset($this->request->get['search'])) {
			$search = $this->request->get['search'];
		} else {
			$search = '';
		} 	
		var_dump($search);
		
		//print_r($this->request->get['search']);
		
		$data['search'] = $search;
Sorry for posting partial code. Yes I have $data['search'] = $search;.

When using var_dump I get this:

string(3) "car"

In view / common / search.twig
<input type="text" name="search" value="{{ search }}" placeholder="Search" class="searchinput" />

value="{{ search }}" always showing "a" no matter what is searched. Even though in controller common/search.php, $data['search'] = $search;, and $search when print_r is showing "car".

Just can't figure where this "a" is coming from.

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by mikeinterserv » Tue Apr 19, 2022 6:17 am

scottyboyyy wrote:
Tue Apr 19, 2022 5:09 am

Code: Select all

if (isset($this->request->get['search'])) {

In view / common / search.twig
<input type="text" name="search" value="{{ search }}" placeholder="Search" class="searchinput" />

value="{{ search }}" always showing "a" no matter what is searched. Even though in controller common/search.php, $data['search'] = $search;, and $search when print_r is showing "car".
Just can't figure where this "a" is coming from.
Its possible these are your issue. Your search is non standard is it ?
Shouldn't placeholder be

Code: Select all

placeholder="{{ text_search }}"
and class

Code: Select all

class="form-control input-lg"
Whatever the reason for these differences I think thats where the problem is.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by by mona » Tue Apr 19, 2022 4:36 pm

scottyboyyy wrote:
Tue Apr 19, 2022 5:09 am
Sorry for posting partial code.
No problem but, what are you doing to $search in the "...... lots of stuff here ....” being more to the point

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am
Who is online

Users browsing this forum: Amazon [Bot] and 75 guests