Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2009
    Posts
    86
    Plugin Contributions
    0

    Default 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.

    Code:
    $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%\'>&nbsp;</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:

    Code:
    $("#prodtable tr").mouseover(function(){
    				$(this).removeClass('nothighlighted');
    				$(this).addClass('highlighted');
    			});
    			$("#prodtable tr").mouseout(function(){
    				$(this).removeClass('highlighted');
    				$(this).addClass('nothighlighted');
    			});
    Code:
    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:
    PHP Code:
    $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.
    Thanks in advance
    Jeff

  2. #2
    Join Date
    Jan 2004
    Posts
    66,419
    Blog Entries
    7
    Plugin Contributions
    277

    Default 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.

  3. #3
    Join Date
    Jun 2009
    Posts
    86
    Plugin Contributions
    0

    Default 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.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,419
    Blog Entries
    7
    Plugin Contributions
    277

    Default 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.

  5. #5
    Join Date
    Jun 2009
    Posts
    86
    Plugin Contributions
    0

    Default Re: custom search page using defined page with ajax

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

  6. #6
    Join Date
    Jan 2004
    Posts
    66,419
    Blog Entries
    7
    Plugin Contributions
    277

    Default 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.

  7. #7
    Join Date
    Jun 2009
    Posts
    86
    Plugin Contributions
    0

    Default 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.

 

 

Similar Threads

  1. v150 Trying to create a single PHP page with ajax without template elements
    By ailtait in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 16 Aug 2012, 05:07 PM
  2. Custom Page with search results
    By tini1709 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 4 Nov 2010, 10:45 AM
  3. Page Not Found Custom 404 Error Page with Site Map Sample Text
    By derek53 in forum Basic Configuration
    Replies: 5
    Last Post: 25 May 2010, 10:16 AM
  4. Custom ajax Search Field Not Populating After Upgrade
    By saddlemen in forum Upgrading from 1.3.x to 1.3.9
    Replies: 3
    Last Post: 19 May 2010, 06:07 PM
  5. New Page adding - using Defined Pages
    By shawnchr in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 1 Jul 2009, 04:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR