# Add current URL in hiddent form input

**URL:** <https://forum.mautic.org/t/add-current-url-in-hiddent-form-input/29387>\
**Category:** Product Support\
**Tags:** mautic-4\
**Created:** [September 21, 2023, 2:30pm UTC](https://forum.mautic.org/t/add-current-url-in-hiddent-form-input/29387 "2023-09-21T14:30:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeckel](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jeckel/32/10573_2.png) [@jeckel](https://forum.mautic.org/u/jeckel)\
**Post date:** [September 21, 2023, 2:30pm UTC](https://forum.mautic.org/t/add-current-url-in-hiddent-form-input/29387/1 "2023-09-21T14:30:24Z")

</div>

**Your software**  
My Mautic version is: 4.9 (official docker image)

**Your problem**  
I want to create a custom form to add in multiple pages. Then I’d like to automatically add the page url (or title) in the submited data.

Is there any tricks to do that ? Builtin feature or custom javascript on form submit event ?

---

<div class="post-metadata">

**Author:** ![ricfreire](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ricfreire/32/14973_2.png) [@ricfreire](https://forum.mautic.org/u/ricfreire)\
**Post date:** [September 21, 2023, 4:25pm UTC](https://forum.mautic.org/t/add-current-url-in-hiddent-form-input/29387/2 "2023-09-21T16:25:26Z")

</div>

Hi Jeckel,

Welcome to the Mautic forum!

I came across an article that I believe could be quite helpful to you: [Tracking Visitor Data by Smart URL](https://www.mautic.org/blog/developer/tracking-visitor-data-by-smart-url)

While using a custom form theme allows you to insert JavaScript, you can also achieve this with a form field called “HTML Area”. That field provides you with the flexibility to include scripts and other HTML elements.

I hope you find this information helpful and that it assists you with your problem!

---

<div class="post-metadata">

**Author:** ![jeckel](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jeckel/32/10573_2.png) [@jeckel](https://forum.mautic.org/u/jeckel)\
**Post date:** [September 21, 2023, 5:16pm UTC](https://forum.mautic.org/t/add-current-url-in-hiddent-form-input/29387/3 "2023-09-21T17:16:03Z")

</div>

Thanks a lot, it seems to fit what I need, I will try this and leave a comment here if it works (and how I made it works)

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [September 25, 2023, 1:24pm UTC](https://forum.mautic.org/t/add-current-url-in-hiddent-form-input/29387/4 "2023-09-25T13:24:17Z")

</div>

You can place a HTML field in the mautic form with this content:

```auto
<script>
(function(global, document) {

    function load() {

        if(!window.MauticFormValidations) return setTimeout(load, 50);
    
        //Config field name and form selector 
        var formSelectorName = 'form';
        var fieldName = 'form_url';
    
        var mauticForms = document.querySelectorAll(formSelectorName);
        for (i = 0;i<mauticForms.length; ++i) 
        {
            var formId = mauticForms[i].getAttribute('data-mautic-form');
            if(!formId)
            {
                continue;
            }
    
            var formField = document.querySelector("form#mauticform_"+formId+" [name=mauticform\\["+fieldName+"\\]");
            if(!formField)
            {
                continue;
            }
    
            if (typeof window.MauticFormCallback == 'undefined') {
                window.MauticFormCallback = {};
            }
    
            MauticFormCallback[formId] = {
                onValidateEnd: function (formValid) {
                  formField.value = window.location.href;
                }
            };  
    
        }
                
    }

    //if document is already ready: start if not: install event handler 
    "loading" === document.readyState ? document.addEventListener("DOMContentLoaded", load) : load(); 
    
}(window, document));
</script>

```

It should set the field “form\_url” with the current site url

---

<div class="post-metadata">

**Author:** ![mojo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mojo/32/543_2.png) [@mojo](https://forum.mautic.org/u/mojo)\
**Post date:** [May 30, 2024, 1:48pm UTC](https://forum.mautic.org/t/add-current-url-in-hiddent-form-input/29387/5 "2024-05-30T13:48:13Z")

</div>

I am looking for exactly such a solution to “capture” the URL of the page where the user completed the form or “capturing” form’s page name.

@jeckel  
Were you able to solve the problem?  
Will you share your solution?

I assume that this code should be added to the form by creating a new “HTML area” field and inserting the code there?  
I tested it and unfortunately it doesn’t work ☹

Or should this code be placed with the code of the form inserted on the page?

@sfahrenkrog1 , please help

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [May 31, 2024, 7:49am UTC](https://forum.mautic.org/t/add-current-url-in-hiddent-form-input/29387/7 "2024-05-31T07:49:13Z")

</div>

Hello

The javascript code i provided must be inserted in the html area of a form field.

Please adapt the form field name to match your form.

Do you have an url for me? I would like to see it.

I could take a look on it on monday.

Greetings  
Sebastian
