简体   繁体   English

如何在不在body标签中放置onload事件的情况下提交表单

[英]How to submit a form without putting an onload event in the body tag

I have several forms synced to Salesforce currently running on a WordPress website using the Avada theme, but the client wants a new field added which will require adding an onload event in the body tag. 我有几个表单已同步到当前使用Avada主题在WordPress网站上运行的Salesforce,但客户端需要添加一个新字段,这需要在body标签中添加onload事件。 I thought the easiest way to do this would be to go through the dashboard>Theme Options>Advanced>Code Fields but I don't see an option to add an event to the body tag. 我认为最简单的方法是通过仪表板>主题选项>高级>代码字段,但我没有看到添加事件到body标签的选项。 What's the best way to do this without editing the core template files (the forms are only on a few pages)? 如果不编辑核心模板文件(表单只在几页上),最好的方法是什么?

Snippet of current code: 当前代码片段:

<form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST"><input type=hidden name="oid" value="00DU0000000H99p">
    <input type=hidden name="retURL" value="https://www.sablesys.com/thank-you/">
    <input type="hidden" name="member_status" value="Sent"/>
    <!-- Campaign id for Quote Campaign -->
    <input type="hidden" name="Campaign_ID" value="7010B000001Eiz3QAC" />
    <input type="hidden" id="lead_source" name="lead_source" value="Website">  
                <label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" required/><br>
        <label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" required/><br>
        <label for="company">Company</label><input id="company" maxlength="40" name="company" size="20" type="text" required/><br>
        <label for="email">Email</label><input id="email" maxlength="80" name="email" size="20" type="text" required/><br>
        <label for="city">City</label><input id="city" maxlength="40" name="city" size="20" type="text" required/><br>

        Notes:<br><textarea id="00NU0000003mN8A" name="00NU0000003mN8A" rows="25" type="text" wrap="soft" style="width: 100%"></textarea><br>
        <input type="submit" name="submit">
</form>

New code the client requested be added: 客户端请求添加的新代码:

A new field for the form: 表单的新字段:


<input type="hidden" id="URL" name="URL" value="" >

A new onload event: 一个新的onload事件:

<body onload="document.getElementById('URL').value = document.location.href">

Is there a way to do a window.onload inside a script instead? 有没有办法在脚本中执行window.onload? I admit I don't know javascript well. 我承认我不懂javascript。 Please be descriptive in your replies. 请在回复中说明。 Thanks. 谢谢。

This line of code IS javascript. 这行代码是javascript。

document.getElementById('URL').value = document.location.href;

You just need a way to get it executed. 你只需要一种方法来执行它。

If any other javascript code is executing on your page, make it part of that. 如果您的页面上正在执行任何其他JavaScript代码,请将其作为其中的一部分。 You could add an "onsubmit" event to the form, like so: 您可以在表单中添加“onsubmit”事件,如下所示:

<form onsubmit="FillInURL()">
<input id="URL" type=hidden>
</form>

function FillInURL() {document.getElementById('URL').value = document.location.href;}

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

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