如何将表单输入数据附加为字符串以形成操作URL

时间:2013-05-16 19:35:53

标签: html forms mailchimp

我有一个mailchimp表单,我需要在我的网站上填写简单html表单中的内容。

我在mailchimp documentation中读到,通过将查询变量附加到网址可以实现这一点。

所以我需要这样的东西:

http://mb30.us7.list-manage1.com/subscribe/post?u=e0bf770a88286aad599b3e945&id=f3cc462828&MERGE1=name&MERGE2=June%205th%20-%208pm%20EST/5pm%20PST&MERGE0=mail

我需要从下面的表单中获取url:

<form action="http://mb30.us7.list-manage1.com/subscribe/post?u=e0bf770a88286aad599b3e945&amp;id=f3cc462828" method="post" name="" target="_blank" novalidate="">
      <h5>1. Which day do you want to attend?</h5>
      <select name="time" style="display: none;">
            <option value="May_20th_-_8pm_EST/5pm_PST">May 20th - 8pm EST/5pm PST</option>
            <option value="May_25th_-_8pm_EST/5pm_PST">May 25th - 8pm EST/5pm PST</option>
            <option value="May_29th_-_8pm_EST/5pm_PST">May 29th - 8pm EST/5pm PST</option>

      </select><div class="ddContainer" style="position:relative;"><a href="#" class="ddToggle" style="width: 200px;">May 20th - 8pm EST/5pm PST<span></span></a><ul class="ddOptionList" style="display: none; top: 48px; width: 223px;"><li class="ddOption"><a class="selected" href="#" rel="May_20th_-_8pm_EST/5pm_PST" style="padding-left: 4px;">May 20th - 8pm EST/5pm PST</a></li><li class="ddOption"><a class="" href="#" rel="May_25th_-_8pm_EST/5pm_PST" style="padding-left: 4px;">May 25th - 8pm EST/5pm PST</a></li><li class="ddOption"><a class="" href="#" rel="May_29th_-_8pm_EST/5pm_PST" style="padding-left: 4px;">May 29th - 8pm EST/5pm PST</a></li></ul></div>

      <h5>2. Where to send the invitation:</h5>
      <input type="text" class="inputbg" onfocus="if (this.value == 'Your Name') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Your Name';}" value="Your Name">
      <input type="email" name="EMAIL" class="inputbg" onfocus="if (this.value == 'Your Email Address') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Your Email Address';}" value="Your Email Address">
      <input type="submit" class="submit" value="Register">
</form>

但如果我将表单更改为get,则无法使其工作,而不是要求u =和id =删除。

1 个答案:

答案 0 :(得分:1)

不是将值添加到URL,而是为这些值创建隐藏的<input>。这就是this example也做的事情(查看来源)。

<input type="hidden" name="u" value="e0bf770a88286aad599b3e945" />
<input type="hidden" name="id" value="f3cc462828" />