douduan9129 2017-05-29 02:42
浏览 168

将文本字段值传递给表单中的url参数

We are trying to register users to a webinar and the only way to do it is via a one-click registration link that is normally used on an email. But we need to use this link on an optin form as well.

https://register.webinar.com/auto-register?webid=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=1

We have three schedules to choose from and this is set on the parameter 'schedule=X'

I'm using radio button with onclick action so that the submit link will changed based on the schedule chosen. e.g.

<form accept-charset="UTF-8" action="submit.php" method="POST" id="myForm">
    <label for="FirstName">First Name *</label>
    <input id="FirstName" name="FirstName" type="text" />
    <label for="Email">Email *</label>
    <input id="Email" name="Email" type="text" />
    <div class="radio_form">
            <input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=1" onclick="javascript:document.getElementById('next_url').href=this.value;" checked="checked">
            <label>Schedule 1</label>

            <input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=2" onclick="javascript:document.getElementById('next_url').href=this.value;">
            <label>Schedule 2</label>

            <input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=3" onclick="javascript:document.getElementById('next_url').href=this.value;">
            <label>Schedule 3</label>
    </div>
<div class="submit_form">
    <a id="next_url" name="next_url" href="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=1" onclick="document.getElementById('myForm').submit();">Submit</a>

Now the other issue, how can I pass the field values for the name and email on the registration link before they click on the submit button? I thought of using onchange for the text fields but I don't know how to pass the info in the url parameter of the registration link.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dougu1985 2017-05-29 06:20
    关注

    You can access url parameters and use those to populate form fields like this -

    <form accept-charset="UTF-8" action="submit.php" method="POST" id="myForm">
    <label for="FirstName">First Name *</label>
    <input id="FirstName" name="FirstName" type="text" />
    <label for="Email">Email *</label>
    <input id="Email" name="Email" type="text" />
    <div class="radio_form">
            <input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=1" onclick="javascript:document.getElementById('next_url').href=this.value;" checked="checked">
            <label>Schedule 1</label>
    
            <input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=2" onclick="javascript:document.getElementById('next_url').href=this.value;">
            <label>Schedule 2</label>
    
            <input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=3" onclick="javascript:document.getElementById('next_url').href=this.value;">
            <label>Schedule 3</label>
    </div>
    <div class="submit_form">
        <a id="next_url" name="next_url" href="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=1" onclick="document.getElementById('myForm').submit();">Submit</a>
    </div>
        </form>
    
        <script>
        var getUrlParameter = function getUrlParameter(sParam) {
            var sPageURL = decodeURIComponent(window.location.search.substring(1)),
                sURLVariables = sPageURL.split('&'),
                sParameterName,
                i;
    
            for (i = 0; i < sURLVariables.length; i++) {
                sParameterName = sURLVariables[i].split('=');
    
                if (sParameterName[0] === sParam) {
                    return sParameterName[1] === undefined ? true : sParameterName[1];
                }
            }
        };
    
        var webid = getUrlParameter('webid');
        var firstName = getUrlParameter('firstname');
        var email = getUrlParameter('email');
        var schedule = getUrlParameter('schedule');
    
        document.getElementById("FirstName").value = firstName;
        document.getElementById("Email").value = email;
        </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败