forms icon indicating copy to clipboard operation
forms copied to clipboard

Prefill fields from url-parameters

Open mr-itbiz opened this issue 4 years ago • 9 comments

Nextcloud (please complete the following information):

  • Nextcloud-Version: [e.g. 20.0.0]
  • Forms-Version: [e.g. 2.0.4]

Hello it is possible to send values for a Form via get? I have a form with the field name and I want to create a link like /index.php/apps/forms/eQHeX2MT6MbfErg4zwztzf?name=Anton

it is possible? Thank you

mr-itbiz avatar Oct 15 '20 11:10 mr-itbiz

To make the business value a bit clear:

With this feature you can create auto generated Form-Links for customers with prefilled user IDs or so.

sethiele avatar Mar 05 '21 09:03 sethiele

+1 from me, too.

Would be really nice for mailings to populate customer ids

RedTiger26 avatar Mar 09 '21 20:03 RedTiger26

+1

This Feature would be really awesome, also it would be an advantage over microsoft and google forms as they are also not supporting this.

nabl13 avatar Jun 10 '21 15:06 nabl13

@nabl13

This Feature would be really awesome, also it would be an advantage over microsoft and google forms as they are also not supporting this.

gforms does support this, see https://trevorfox.com/2015/06/dynamically-pre-fill-google-forms-with-mailchimp-merge-tags/

KiaraGrouwstra avatar Aug 23 '22 14:08 KiaraGrouwstra

there are a few components to this:

  • ensuring form inputs have sane id attributes, preferably based on the question. this appears related to #1040.
  • populating the inputs from query parameters, which comes down to:
var params = (new URL(document.location)).searchParams;
for (var [param_key, param_value] of params.entries()) {
    var formElement = document.getElementById(param_key);
    if (formElement) {
        formElement.value = param_value;
    }
}
  • (bonus) potentially facilitating generating such prefilled URLs from the UI

KiaraGrouwstra avatar Jan 21 '23 22:01 KiaraGrouwstra

Hi @KiaraGrouwstra

if you want you can give it a try and work on this :) We would be very happy if you can create a PR for this issue :)

Chartman123 avatar Jan 22 '23 01:01 Chartman123

Given the development in #1382, is this still the suggested approach for implementing this? I could see the two methods interfering with each other. I assume the localStorage should take precedence?

there are a few components to this:

var params = (new URL(document.location)).searchParams;
for (var [param_key, param_value] of params.entries()) {
    var formElement = document.getElementById(param_key);
    if (formElement) {
        formElement.value = param_value;
    }
}
  • (bonus) potentially facilitating generating such prefilled URLs from the UI

Schlepptop avatar Oct 16 '23 21:10 Schlepptop

@Schlepptop that sounds like a question of user intent. i wonder if there is an easy answer there.

KiaraGrouwstra avatar Oct 16 '23 22:10 KiaraGrouwstra

The safest approach would probably be to handle this with a modal as in #1310.

Schlepptop avatar Oct 16 '23 22:10 Schlepptop