You are here:  » Is there a way to Insert the [category] into a js form?

Active Forum Topics

Is there a way to Insert the [category] into a js form?

Submitted by 2fer on Sat, 2015-10-03 17:56 in

Hi David,
I'm using an ad in my footer.php that uses a form to display additional products. I can hard code a broad variable, but then results are from random products. I would have their products in the same shop, but the datafeed is too horrible. I'd like to be able to populate one form field with the [category] of the product or products shown. You can see from my examples here, I have no clue how to do this. I would need to get it into:
default_category = "[this space]";

I wondered if it would work with something like:
default_category = "<?php print ["category"]." "?>";

If that is a bad idea for some reason, I can create a different field with the same terms but a different name.

I understand if you can't help with this one.
Thanks for great suport!

Submitted by support on Sun, 2015-10-04 09:36

Hello 2fer,

There are two ways that a category value could be in context within html/footer.php - either from being on a product page (via $product_main["category"]) or a category search results page.

To pull either and then populate your form code, including a conditional so that it is only displayed when a category is in context, have a go with something like;

  if (isset($product_main["category"]))
    $footer_category = $product_main["category"];
  elseif(isset($searchresults) && ($parts[0]=="category"))
    $footer_category = $parts[1];
    $footer_category = "";
<?php if ($footer_category): ?>
  <!-- form JS code here including: -->
  default_category = "<?php print $footer_category?>";
<?php endif; ?>


Submitted by 2fer on Mon, 2015-10-05 18:22

Hi David,
I currently have it within the shop section of the footer.php and was wishing I had a way to only have it show on either category search results or product pages, so this would work out even better than the basic fix I had hoped for!

Thank you for your help and always great support!