Forums / Code Collaboration / custom search page using defined page with ajax

custom search page using defined page with ajax

Views: 3,558

Results 1 to 7 of 7
14 Feb 2013, 6:57 PM
#1
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

custom search page using defined page with ajax

I am trying to write a custom search page for a client using ajax with php to kind of find all containing "XXX" then selcting a part in the table will give you details below, all is going well using define_page_3.php and a custom jquery script in jscript_parts_lookup,php.
I can enter a partial part number and i lists all results in a table, however when i select the row to show the details, I am having an issue.

$theProductId = $_POST['pn'];
global $db;

if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
		if (isset($_POST['pn']) === true && empty($_POST['pn']) === false) {
		$sql = 'select * from ' . TABLE_PRODUCTS . ' where products_model like :modelID:';
		$sql = $db->bindVars($sql, ':modelID:', '%' . $theProductId . '%', 'string');
		$result = $db->Execute($sql);
		echo '<table class="prodtable" id="prodtable">';
		echo '<tr class="tbhr"><th width=\'15%\'>PN:</th><th width=\'35%\'> Desc</th><th width=\'5%\'> </th></tr>';
		if ($result->RecordCount() > 0) {
			while (!$result->EOF) {
				echo '<tr>';
				echo '<td>';
			    echo '<p>' . $result->fields['products_model'].'</p>';
			  	echo '</td>';
				echo '<td>';
					$sql = 'select * from ' . TABLE_PRODUCTS_DESCRIPTION . ' where products_id = :productID:';
					$sql = $db->bindVars($sql, ':productID:', $result->fields['products_id'] , 'string');
					$result1 = $db->Execute($sql);
					echo $result1->fields['products_description'];
				echo '</td>';
				echo '</tr>';
			  $result->MoveNext();
			}
		echo '</table>';
		} else {
			echo 'Sorry, no record found for product number ' . $theProductId;
		}
		} else {
			echo 'Please enter a valid part number';
		}

the jscript:

$("#prodtable tr").mouseover(function(){
				$(this).removeClass('nothighlighted');
				$(this).addClass('highlighted');
			});
			$("#prodtable tr").mouseout(function(){
				$(this).removeClass('highlighted');
				$(this).addClass('nothighlighted');
			});
var tr = $('#prodtable').find('tr');
            tr.bind('click', function(event) {
                var partnum = '';
                tr.removeClass('highlighted');
                var tds = $(this).addClass('highlighted').find('td');
                var ptxt = $(this).find('p');

                $.each(ptxt, function(index, item) {
					 partnum = partnum + (item.innerText || item.textContent);
                });
               	$.post('../includes/languages/english/html_includes/ojl/define_page_3.php', {partnum: partnum}, function(data){						
						$('#part_detail').html(data);
					});
            });

Now when selecting a row, i get this error:
Fatal error: Call to a member function bindVars() on a non-object in /home/content/xxx/html/includes/languages/english/html_includes/ojl/define_page_3.php on line 48

which is line:

$sql = $db->bindVars($sql, ':modelID:', $tvalue, 'string');

Which doesnt make any sence to me because what i gather formt the error is that is doesnt see the $db object which is clearly used in the above section of code to make the table?
Any clues? ive been on this 2 days now and its greatly holding me up.:wacko::wacko::frusty::frusty:
Thanks in advance
Jeff

14 Feb 2013, 8:57 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: custom search page using defined page with ajax

For security reasons you should NEVER make calls from the browser or ajax to any .php files under the /includes/ folder.
That's why the /includes/.htaccess file specifically blocks that.

Your problem is directly because the define_page_3.php file (which is nested below the /includes/ folder) doesn't know anything about anything else in Zen Cart itself.

Your $.post call should be to /index.php?main_page=page_3

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

14 Feb 2013, 10:25 PM
#3
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: custom search page using defined page with ajax

Thank you that was absolutely it, now if i can get it to stop redrawing the entire page when it posts back lol.

15 Feb 2013, 12:54 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: custom search page using defined page with ajax

Well, that's gonna be complicated, since all those parts are included in the drawing of the page. You should probably put the business logic in another file. It's REALLY not intended that define-pages would be used for the purpose you're attempting.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

15 Feb 2013, 12:39 PM
#5
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: custom search page using defined page with ajax

So... where would i put that file? Tutorial?

21 Feb 2013, 10:47 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: custom search page using defined page with ajax

Given that your ajax handler file can't put located under the includes folder, putting it someplace above the includes folder (ie the root, which is the same folder where your includes folder is found) would be logical.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Feb 2013, 12:08 PM
#7
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: custom search page using defined page with ajax

yes, it would be logical, just didnt know if it was allowed lol.
I made some custom search forms and sideboxes, simply recreating the standard search forms and renaming them, it works great.
I found in my endeavors that under ../includes/modules/pages, i can recreate a page, and use scripting from there, since this is my overall goal, is just a modified search page with some AJAX to show certain content according to a combo box selection.