简体   繁体   English

如何通过JavaScript将动态URL添加到WordPress中的表单操作?

[英]How to add a dynamic URL to a form action in WordPress via JavaScript?

I need to make a change to a WordPress plugin in how the filled in data is handled. 我需要更改如何处理填充数据的WordPress插件。 When a user hits a submit button I need to set the form action to a generated URL. 当用户点击提交按钮时,我需要将表单操作设置为生成的URL。

The plugin already generates a URL in a hidden field, but I need the value to become the form action URL. 该插件已经在隐藏字段中生成了一个URL,但是我需要该值才能成为表单操作URL。 (I'm quite unexperienced in JS) (我对JS完全没有经验)

The #download URL is the required URL needed to go to the form action. #download URL是执行表单操作所需的URL。

    dataset.updateExistingChurn(), a(), dataset.updateTable(), dataset.updateBoxes();
    n = "";
    if (dataset.isValid()) {
        var n = "https://www.example.com/the-example-difference/";
        n += "?pdf=" + t(s)
    }
    jQuery("#download_url").val(n), "" != n || dataset.isValid() ? jQuery("#submission").removeClass("hide") : jQuery("#submission").addClass("hide")
}), jQuery(window).resize(function() {
    e()
}), dataset.updateExistingChurn(), dataset.updateTable(), dataset.updateBoxes()

}) })

The outcome is that on clicking submit they are directed to the URL. 结果是,单击提交后,它们将定向到URL。 Could you please advise me? 你能告诉我吗?

Try the following snippet: 尝试以下代码段:

$(".submit").on("click", function(e){
    e.preventDefault();
    $('#form').attr('action', "/url").submit();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM