从 url 参数设置表单值

Set form value from url parameter

我正在使用 Typo3 10LTS,我想使用 URL.

中的参数值设置表单字段的值

例如应通过 URL www.test-xyz.de/sidename?field-1=123.

将值“123”输入到表单字段“field-1”中

谢谢, 斯蒂芬

流体

假设我们有一个流体 link,参数为 "123"

<f:link.page pageUid="999" additionalParams="{param: '123'}" noCacheHash="true">Link to Form</f:link.page>

这会将参数发送到带有表单的页面,包含 URL:

中的值
www.test-xyz.de/sitename?param=123

参见:link.page Documentation

jQuery

我们现在可以使用几行 jQuery 来用 URL:

中的值填充一个字段
$(".myForm").each(function() {

    // Function to sanitize output
    
    function getURLParameter(name) {
      return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
    };
    
    // Populate the input field '.field1' with the parameter in the URL

    if (getURLParameter('param') !== null) {
        var value = getURLParameter('param');
        $('.field1').each(function(){ 
            $(this).val(value); 
        }); 
    };

});