[Skip to main content](#vessel-content)

#   PHP to get product name for a form field on product page

##

- **[dda](/forum/user/32554-dda "View dda's Profile")**
- [![dda's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/32554-dda "View dda's Profile") Topic Author
- [ Offline](/forum/user/32554-dda)

Less More

- Posts: 39
- Thank you received: 0
-
-

7 years 7 months ago [\#304906](#304906) by [dda](/forum/user/32554-dda "View dda's Profile")  *[PHP to get product name for a form field on product page](/forum/25-install-update/897146-php-to-get-product-name-for-a-form-field-on-product-page#304906 "-- HikaShop version -- : 4.0.3 -- Joomla version -- : 3.9.3 -- PHP version -- : 7  I need to put a contact form on product pages so a person can submit a contact request regarding the product. For user convenience I want to automatically insert the product name into a field in the contact form.  I am trying to use this to get the product name:  $productName = hikashop&#95;get('product&#95;name'); echo $productName;  It does't return anything and no error occurs on the page. What am I doing wrong?")* was created by *[dda](/forum/user/32554-dda "View dda's Profile")*

-- HikaShop version -- : 4.0.3
-- Joomla version -- : 3.9.3
-- PHP version -- : 7

I need to put a contact form on product pages so a person can submit a contact request regarding the product. For user convenience I want to automatically insert the product name into a field in the contact form.

I am trying to use this to get the product name:

$productName = hikashop_get('product_name');
echo $productName;

It does't return anything and no error occurs on the page. What am I doing wrong?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg5NzE0Ni1waHAtdG8tZ2V0LXByb2R1Y3QtbmFtZS1mb3ItYS1mb3JtLWZpZWxkLW9uLXByb2R1Y3QtcGFnZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86291
- Thank you received: 14269
-
-

7 years 7 months ago [\#304913](#304913) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[PHP to get product name for a form field on product page](/forum/25-install-update/897146-php-to-get-product-name-for-a-form-field-on-product-page#304913 "-- HikaShop version -- : 4.0.3 -- Joomla version -- : 3.9.3 -- PHP version -- : 7  I need to put a contact form on product pages so a person can submit a contact request regarding the product. For user convenience I want to automatically insert the product name into a field in the contact form.  I am trying to use this to get the product name:  $productName = hikashop&#95;get('product&#95;name'); echo $productName;  It does't return anything and no error occurs on the page. What am I doing wrong?")*

Hi,

hikashop_get is a function to initiliaze class instances, not to load elements information. So that code cannot possibly work. You would first have to get the current product id, then load the product class, then load the product data using the product class and then you can echo the product name.
Supposing that you're on the product page, you can use such code to do that: Code:

$product_id = (int)hikashop_getCID('product_id'); $class = hikashop_get('class.product'); $product = $class-&gt;get($product_id); echo $product-&gt;product_name;

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg5NzE0Ni1waHAtdG8tZ2V0LXByb2R1Y3QtbmFtZS1mb3ItYS1mb3JtLWZpZWxkLW9uLXByb2R1Y3QtcGFnZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[dda](/forum/user/32554-dda "View dda's Profile")**
- [![dda's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/32554-dda "View dda's Profile") Topic Author
- [ Offline](/forum/user/32554-dda)

Less More

- Posts: 39
- Thank you received: 0
-
-

7 years 7 months ago [\#304957](#304957) by [dda](/forum/user/32554-dda "View dda's Profile")  Replied by *[dda](/forum/user/32554-dda "View dda's Profile")* on topic *[PHP to get product name for a form field on product page](/forum/25-install-update/897146-php-to-get-product-name-for-a-form-field-on-product-page#304957 "-- HikaShop version -- : 4.0.3 -- Joomla version -- : 3.9.3 -- PHP version -- : 7  I need to put a contact form on product pages so a person can submit a contact request regarding the product. For user convenience I want to automatically insert the product name into a field in the contact form.  I am trying to use this to get the product name:  $productName = hikashop&#95;get('product&#95;name'); echo $productName;  It does't return anything and no error occurs on the page. What am I doing wrong?")*

Thanks Nicolas that code works on a menu item that goes direct to a product page.

However, it isn't working correctly on a product page that is accessed via a Categories listing menu item (which is how I need it to work).

I have PM you with further details.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg5NzE0Ni1waHAtdG8tZ2V0LXByb2R1Y3QtbmFtZS1mb3ItYS1mb3JtLWZpZWxkLW9uLXByb2R1Y3QtcGFnZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86291
- Thank you received: 14269
-
-

7 years 7 months ago -  7 years 7 months ago [\#304958](#304958) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[PHP to get product name for a form field on product page](/forum/25-install-update/897146-php-to-get-product-name-for-a-form-field-on-product-page#304958 "-- HikaShop version -- : 4.0.3 -- Joomla version -- : 3.9.3 -- PHP version -- : 7  I need to put a contact form on product pages so a person can submit a contact request regarding the product. For user convenience I want to automatically insert the product name into a field in the contact form.  I am trying to use this to get the product name:  $productName = hikashop&#95;get('product&#95;name'); echo $productName;  It does't return anything and no error occurs on the page. What am I doing wrong?")*

Hi,

The link you gave on your pm is not a product page. It's a category page. It displays a listing of the products of a category. And the id in the URL is the id of a category, not of a product.
So the first line of my code, which gets the id in the URL actually uses that category id as a product id.
I'm not sure what you're trying to do here.
Since it's a listing of products of a category, the list of the products is not available outside of the view files displaying the products listing.
If you add your code in the listing_img_title file of the product view via the menu Display&gt;Views and change that first line to:
$product_id = $this-&gt;row-&gt;product_id;
then you'll get the product name of the current product for each product displayed on the listing. But since the product data is already loaded there, you could simply do:
echo $this-&gt;row-&gt;product_name;

PS: Please use instead our contact form and include a link to this thread in your message:
[ www.hikashop.com/support/contact-us.html](https://www.hikashop.com/support/contact-us.html)

Last edit: 7 years 7 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg5NzE0Ni1waHAtdG8tZ2V0LXByb2R1Y3QtbmFtZS1mb3ItYS1mb3JtLWZpZWxkLW9uLXByb2R1Y3QtcGFnZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop- Install &amp; Update- Product &amp; Category Display- Content Creation- Sales and Orders- - Orders management- - Reports &amp; Statistics- Customers- Checkout- Payment Methods- Shipping Methods- Import &amp; Export (CSV, XLS…)- Specific Features- - Affilation- - Taxes- - Wishlist- - Vote- - Carousel &amp; Slider- - Mass Actions- - Filters &amp; Search- - Discount &amp; Coupon- - Feature Request- Integrations- Showcase- General Talk about HikaShop- Development- - HikaShop 3.0 Beta- Translation- Commercial Jobs HikaShop Components- HikaMarket- - Market: Feature requests- - Market: How to?- - Market: Bug Report- HikaSerial- - General talk about HikaSerial- - Serial: Bug Report- - Serial: How to?- - Support en Français de HikaSerial (French Support)- - HikaSubscription- HikaAuction- - Auction: Feature requests- - Auction: How to?- - Auction: Bug report Hikashop around the world- Support en Français (French Support)- Russian- - FAQ. Курс выживания с Hikashop. Частые вопросы и о- - Расширения Hikashop- - Наши сайты на Hikashop- 日本語版サポート(Japanese Support)- Thai- German Archives- Bug Report- How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.159 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
