表单未发送,POST

huangapple go评论59阅读模式
英文:

Form not sending, POST

问题

I have my form

<form class="newsletter" action="https://sendy.thegoodfellas.net/sendy/subscribe" method="POST" accept-charset="utf-8">
  <span class="container active">
    <label for="name">What's your name?</label>
    
    <input class="required" type="text" name="name" id="name"/>
    <span class="next" title="next"></span>
  </span>
  <span class="container">
    <label for="email">What's your email?</label>
    <input class="required" type="email" name="email" id="email"/>
  </span>
  <span class="submit" type="submit" name="submit" id="submit"></span>
</form>

and the JS

$('.next').click(function(){
  var nextTarget = $(this).parent().siblings('span');
  var currentTarget = $(this).parent();
  currentTarget.removeClass('active');
  nextTarget.addClass('active').find('input').focus();
});
    
$('input#email').on('keydown',function(e){
  var keyCode = e.keyCode || e.which; 
  if (keyCode == 13) {
    $('.submit').trigger('click');
  }
})
    
$('.submit').click(function(){
  var target = $(this);
  var lastInputContainerLabel = target.parent().find('.container.active label');
  target.addClass('submitted');
  lastInputContainerLabel.addClass('fadeOut');
})

But for some reason, when the form is submitted I do not see the post call in the network. Nothing is sent.

https://thegoodfellas.net/beatsoutsideblockparty/

How should I debug it?

英文:

I have my form

<form class="newsletter" action="https://sendy.thegoodfellas.net/sendy/subscribe" method="POST" accept-charset="utf-8">
  <span class="container active">
    <label for="name">What's your name?</label>
    
    <input class="required" type="text" name="name" id="name"/>
    <span class="next" title="next"></span>
  </span>
  <span class="container">
    <label for="email">What's your email?</label>
    <input class="required" type="email" name="email" id="email"/>
  </span>
  <span class="submit" type="submit" name="submit" id="submit"></span>
</form>

and the JS

$('.next').click(function(){
  var nextTarget = $(this).parent().siblings('span');
  var currentTarget = $(this).parent();
  currentTarget.removeClass('active');
  nextTarget.addClass('active').find('input').focus();
});
    
$('input#email').on('keydown',function(e){
  var keyCode = e.keyCode || e.which; 
  if (keyCode == 13) {
    $('.submit').trigger('click');
  }
})
    
$('.submit').click(function(){
  var target = $(this);
  var lastInputContainerLabel = target.parent().find('.container.active label');
  target.addClass('submitted');
  lastInputContainerLabel.addClass('fadeOut');
})

But for some reason, when the form is submitted I do not see the post call in the network. Nothing is sent.

https://thegoodfellas.net/beatsoutsideblockparty/

How should I debug it?

答案1

得分: 1

This line of HTML:

<span class="submit" type="submit" name="submit" id="submit"></span>

不合法。type="submit" 不是元素的已识别属性。

你真正有两个选择:
a) 将你的 "submit" 元素改为元素(并根据需要进行样式设置),或者 b) 在你的JavaScript代码中添加一行额外的代码来实际提交表单。

$('.submit').click(function(){
  var target = $(this);
  var lastInputContainerLabel = target.parent().find('.container.active label');
  target.addClass('submitted');
  lastInputContainerLabel.addClass('fadeOut');
  document.forms[0].submit();
})

或者,如果给你的 "submit" 元素一个ID,然后你可以通过该ID直接引用它(如果你的页面中有多个表单,这特别有用,以确保你提交的是正确的一个)。

例如:

<span class="submit" id="submitSpan">Submit Me</span>

document.getElementById('submitSpan').submit();
英文:

This line of HTML:

&lt;span class=&quot;submit&quot; type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit&quot;&gt;&lt;/span&gt;

is not valid. type="submit" is not a recognised attribute of a &lt;span&gt; element.

You really have two choices:
a) change your &lt;span&gt; "submit" element to an &lt;input&gt; element (and style it as required), or b) add an extra line in your javascript code to actually submit the form

$(&#39;.submit&#39;).click(function(){
  var target = $(this);
  var lastInputContainerLabel = target.parent().find(&#39;.container.active label&#39;);
  target.addClass(&#39;submitted&#39;);
  lastInputContainerLabel.addClass(&#39;fadeOut&#39;);
  document.forms[0].submit();
})

Alternatively, if you give your &lt;span&gt; "submit" element an ID then you could reference it directly by the ID (particularly useful if you have multiple forms within your page, to be doubly sure you're submitting the correct one)

eg.

&lt;span class=&quot;submit&quot; id=&quot;submitSpan&quot;&gt;Submit Me&lt;/span&gt;

document.getElementById(&#39;submitSpan&#39;).submit();

答案2

得分: 1

你没有提交表单,将 $(&quot;form.newsletter&quot;).submit(); 添加到 $(&#39;.submit&#39;).click 函数中。

$(&#39;.submit&#39;).click(function(){
  var target = $(this);
  var lastInputContainerLabel = target.parent().find(&#39;.container.active label&#39;);
  target.addClass(&#39;submitted&#39;);
  lastInputContainerLabel.addClass(&#39;fadeOut&#39;);
  //---添加这部分------
  $(&quot;form.newsletter&quot;).submit();
})
英文:

You did not submit your form, add $(&quot;form.newsletter&quot;).submit(); in $(&#39;.submit&#39;).click function.

$(&#39;.submit&#39;).click(function(){
  var target = $(this);
  var lastInputContainerLabel = target.parent().find(&#39;.container.active label&#39;);
  target.addClass(&#39;submitted&#39;);
  lastInputContainerLabel.addClass(&#39;fadeOut&#39;);
  //---Add this------
  $(&quot;form.newsletter&quot;).submit();
})

huangapple
  • 本文由 发表于 2023年6月5日 06:00:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76402566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定