AbanteCart Community

General Topics => General Discussion => Topic started by: Marvin C. on August 10, 2025, 11:57:43 PM

Title: When a user submits a form, how can we automatically obtain the url of the page?
Post by: Marvin C. on August 10, 2025, 11:57:43 PM
When a user submits a form, how can we automatically obtain the url of the page?The form is on the product page.I want to automatically obtain the link or product name of the product when the user submits the form.
Title: Re: When a user submits a form, how can we automatically obtain the url of the page?
Post by: Basara on August 11, 2025, 01:28:06 AM
Hello.
If you've added a custom form via the Form Manager, you can do this by adding a hidden input field to your form, then filling it with JavaScript when the page loads.
Title: Re: When a user submits a form, how can we automatically obtain the url of the page?
Post by: yonghan79 on March 11, 2026, 05:09:06 AM
Hi Basara,

where should we put the javacript?
Title: Re: When a user submits a form, how can we automatically obtain the url of the page?
Post by: Basara on March 11, 2026, 11:02:56 AM
Hello.
Put the JavaScript in an HTML block and assign that block to the page layout where the form is shown.

There are other ways to add JavaScript too, such as directly in the template files, but using an HTML block is usually the easier method for this kind of task.
Title: Re: When a user submits a form, how can we automatically obtain the url of the page?
Post by: marktuan on August 07, 2026, 09:12:28 AM
If the form is embedded directly on the product page, you can usually capture the current product URL or product ID when the form is submitted rather than asking the user to enter it.

For example, on the client side, `window.location.href` will give you the current page URL. If you need the product name, it would be better to pass the product ID/name from the product page into a hidden form field and submit it along with the other form data.

In AbanteCart, I'd recommend using the product ID as the reliable value and looking up the product name afterward. URLs and product names can change, while the product ID should remain stable. If you're handling the submission in a controller, you can then use that ID to retrieve the corresponding product information.
Title: Re: When a user submits a form, how can we automatically obtain the url of the page?
Post by: timlight10 on August 14, 2026, 06:33:12 PM
Quote from: Marvin C. on August 10, 2025, 11:57:43 PMWhen a user submits a form, how can we automatically obtain the url of the page?The form is on the product page.I want to automatically obtain the link or product name of the product when the user submits the form.

I am wondering the same question, and curious if the way to do this has changed since this was originally posted.