Autofill Form from URL on Forminator

I Would like to autofill my form getting a URL parameter, like https://www.mysite.co.il/index.php/te/?name=kkkkkk

Can you help me to create the function and implement this using Forminator?

  • Pawel Pela
    • Ex Staff

    Hello Yair!

    I hope you’re well today and thank you for reaching out to us!

    That seems doable. I’ve done someting similar some time ago for a client, actually.

    Just to make sure we’re on the same page: please tell me step by step how the autofill should work. I’m not sure what the kkkkkk parameter is in the URL.

    If I’m right, you want to add a parameter to the URL of a page and then display a form on that page. The form should take the parameter and autofill one of the fields. Is that correct?

    Kind regards,

    Pawel

  • Pawel Pela
    • Ex Staff

    Hello Yair!

    Please check the attached file. It’s a tiny plugin that you can install as any other plugin and activate.

    You can configure two things in it by changing the defines at the beginning of the .php file:

    define("FF_PARAMETER_NAME", "f_name");
    define("FF_FIELD_CLASS", "forminator-name--field");

    First one is the name of the parameter in the URL. Unfortunately, you can’t use “name” because it’s reserved in WordPress and will cause errors (404 Not Found).

    The second one is the class of the input field where the contents of the parameter should go.

    Please test it and tell me if it works as you need.

    Kind regards,

    Pawel

  • Pawel Pela
    • Ex Staff

    Hello Yair!

    That’s great! Happy to hear it works for you, Yair!

    If you need more fields, you’d have to do some copying, although that’s not as straightforward as just copy-paste. Please tell me when you are decided on what fields you need to fill, what are the names etc. and I can make an update for you real quick :slight_smile:

    Cheers,

    Pawel

  • Pawel Pela
    • Ex Staff

    Hello Yair!

    I’ve changed the code so that now you can use how many fields you like. The configuration changed a bit because of this, but I’m sure it’s easy still to grasp.

    $forminator_fields = array(
    // Put the fields here
    // first the URL GET parameter, then the field class in the form
    "f_name" => "forminator-name--field",
    );

    So now what you will need to do is to copy this line “f_name” => “forminator-name–field”, and paste it however many times you need. Don’t forget the comma at the end, or PHP will stop working! :slight_smile: Then fill it by giving the URL GET parameter first and the field’s class next.

    You can check the fields’s class in Chrome or Firefox by right-clicking on the field and selecting “Inspect” – it will be in the class=”some-class” attribute.

    The screenshot you provided is not enough to fill in the fields for you (I need to see what class they have), but I’m sure you’ll manage to do it yourself, also I don’t know what names you want to give to the URL parameters (you can choose almost freely).

    I’ve attached the new version of the plugin to my post here. Please test it and tell me if it worked (works good on my test site).

    Cheers,

    Pawel

  • Pawel Pela
    • Ex Staff

    Hello Yair!

    Right, I see what you mean. I've updated the plugin to instead take the ID of the field, not the class. So now if you right click in Chrome or Firefox on the field and select "Inspect", you will see the HTML code. Look for the id="some-id" in the HTML input field. Please see the attached screenshot.

    In your form those are:

    shem he-khatan has ID name-1-field

    shem ha-hakalah has ID name-2-field

    ketovet has ID text-2-field

    So they are all unique in the form and now they will not be filled multiple times once you set them up. Tested and should work.

    Derishat shalom,

    Pawel

    • Yair Shiloach
      • WPMU DEV Initiate

      Pawel

      Hey again!

      Another question: If I want to use:

      encodeUriComponent

      To avoid problems with special characters,

      What should I add to the plugin you built for me to support? At the moment I see that he is unable to extract the data I am making ENCODEING into the parameters in the link

    • Nahid
      • Ex Staff

      Hey there Abraham !

      Hope you are doing well today!

      Thank you for your query. The small plugin made by my colleague Pawel only serves a small specific purpose requested by a fellow member in this ticket, unfortunately, its use cases are not versatile. Since we are really keen on keeping a ticket specific to one query and one member only in order to ensure a better support experience, could you possibly get in touch with our Support team here so that we can address your request separately? We really appreciate your consideration regarding this. Thanks!

      Kind regards,

      Nahid